Resolved
Resolved in: WPML 4.6.4
Overview of the issue
If you are using Flywheel hosting or ImageMagick, uploading a PDF to your WordPress library gives you a fatal error:
PHP Fatal error: Uncaught Error: Cannot use object of type WP_Error as array in /www/wp-content/plugins/wpml-media-translation/classes/media-translation/class-wpml-media-attachment-image-update.php:61
Workaround
- Make a full backup of your site.
- Edit /wp-content/plugins/wpml-media-translation/classes/media-translation/class-wpml-media-attachment-image-update.php, line 49-76
- Change:
if ( wp_image_editor_supports( array( 'mime_type' => $file['type'] ) ) ) { $editor = wp_get_image_editor( $file['file'] ); if ( ! is_wp_error( $editor ) ) { $size = $editor->get_size(); if ( $size['width'] > 150 || $size['height'] > 150 ) { $resizing = $editor->resize( 150, 150, true ); if ( is_wp_error( $resizing ) ) { wp_send_json_error( $resizing->get_error_message() ); } } $thumb = $editor->save(); if ( ! empty( $thumb ) ) { $uploads_dir = wp_get_upload_dir(); $thumb_url = $uploads_dir['baseurl'] . $uploads_dir['subdir'] . '/' . $thumb['file']; $thumb_path = $thumb['path']; } } else { wp_send_json_error( __( 'Failed to load the image editor', 'wpml-media' ) ); } } elseif ( 0 === strpos( $file['type'], 'image/' ) ) {
To:
if ( wp_image_editor_supports( array( 'mime_type' => $file['type'] ) ) ) { if ( ! extension_loaded( 'imagick' ) && ($file_array["type"] !== "application/pdf")) { $editor = wp_get_image_editor($file['file']); if (!is_wp_error($editor)) { $size = $editor->get_size(); if ($size['width'] > 150 || $size['height'] > 150) { $resizing = $editor->resize(150, 150, true); if (is_wp_error($resizing)) { wp_send_json_error($resizing->get_error_message()); } } $thumb = $editor->save(); if (!empty($thumb)) { $uploads_dir = wp_get_upload_dir(); $thumb_url = $uploads_dir['baseurl'] . $uploads_dir['subdir'] . '/' . $thumb['file']; $thumb_path = $thumb['path']; } } else { wp_send_json_error(__('Failed to load the image editor', 'wpml-media')); } } } elseif ( 0 === strpos( $file['type'], 'image/' ) ) {
Hello,
I have the same issue for the translation of a video but not form Flywheel but from regular hosting.
After replacing the scripts it does load but I do not get it translated on the frontend.
I did removed and add the video & other changes for the same page but this does not work after updating the translation.
Hello there,
Thank you for reporting it, however we need to investigate your situation. Could you please open a ticket in our support forum?
We will be able to help you better there.
Regards
Hello,
One last question about this fix.
Does this fix will be removed when I apply the next WPML update?
Thanks
Hey there,
Yes, there is a possibility that a WPML Media Translation overrides this fix.
We will keep you updated.
Hi, can we have this simple fix included in next update?
It’s hard to maintain websites if we have to hack the original files of the plugins for years.
Thanks,
regards
Hello there,
We understand your situation. This is already in our devs roadmap, we will keep this erratum updated.
Regards
Hi. I also face the same situation.
WordPress uses Imagick by default since WordPress 3.5.0!
It’s been 18 month since this fix exists. How comes it’s not implemented yet in regular WPML media versions?
Hello there,
We understand your situation and this is already in our devs roadmap.
We will keep you updated.
Regards
Hello everyone,
This should be solved with WPML 4.6.4. Don’t hesitate to make a full backup of your site before proceeding.
Cheers!