Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with plugin "Enable Media Replace" broken with WP 5.3 #493

Closed
Screenfeed opened this issue May 6, 2020 · 1 comment · Fixed by #497
Closed

Compatibility with plugin "Enable Media Replace" broken with WP 5.3 #493

Screenfeed opened this issue May 6, 2020 · 1 comment · Fixed by #497

Comments

@Screenfeed
Copy link
Contributor

In its version 3.3.8, the plugin Enable Media Replace changed some things to adapt to WordPress 5.3’s new upload process.
Since this version, our compatibility is broken. Currently, Imagify is hooking 'emr_unfiltered_get_attached_file' to initiate everything:

add_filter( 'emr_unfiltered_get_attached_file', [ \Imagify\ThirdParty\EnableMediaReplace\Main::get_instance(), 'init' ] );

But now in \EnableMediaReplace\Replacer::__construct():

      if (function_exists('wp_get_original_image_path')) // WP 5.3+
      {
          $source_file = wp_get_original_image_path($post_id);
          if ($source_file === false) // if it's not an image, returns false, use the old way.
            $source_file = trim(get_attached_file($post_id, apply_filters( 'emr_unfiltered_get_attached_file', true )));
      }
      else
        $source_file = trim(get_attached_file($post_id, apply_filters( 'emr_unfiltered_get_attached_file', true )));

If wp_get_original_image_path() doesn’t return false, the hook 'emr_unfiltered_get_attached_file' is not triggered anymore.

This results in the images being improperly optimized, and the old backup file + old webp images not being replaced.
Plugin.

@Screenfeed
Copy link
Contributor Author

Scope a solution
Hook 'wp_handle_replace' instead of 'emr_unfiltered_get_attached_file'. The only downside is that this hook is located outside the class EnableMediaReplace\Replacer. The perfect solution would be to have a hook available at the beginning of EnableMediaReplace\Replacer->replaceWith(). Since the hook 'wp_handle_replace' is always used before creating a new instance of Replacer, it will work. This hook is also used by ShortPixel.

Effort
Effort [S]

@Screenfeed Screenfeed self-assigned this May 11, 2020
@Screenfeed Screenfeed added this to the 1.9.10 milestone May 11, 2020
@Screenfeed Screenfeed removed their assignment May 15, 2020
@remyperona remyperona mentioned this issue May 26, 2020
remyperona added a commit that referenced this issue May 26, 2020
- Bugfix: Correctly optimize thumbnails during auto-optimization of image upload (#491)
- Bugfix: Fix broken compatibility with Enable Media Replace plugin after WordPress 5.3 (#493)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant