WPML

Обзор проблемы

Если Вы используете хостинг Flywheel или ImageMagick, загрузка PDF-файла в Вашу библиотеку WordPress приводит к фатальной ошибке:

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

Обходное решение

Эта проблема исправлена в WPML 4.6.4. Обновление решает эту проблему на Вашем сайте, поэтому это обходное решение понадобится Вам, только если Вы пока не можете выполнить обновление.

  1. Сделайте полную резервную копию Вашего сайта.
  2. Отредактируйте /wp-content/plugins/wpml-media-translation/classes/media-translation/class-wpml-media-attachment-image-update.php, строки 49–76
  3. Замените:
    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/' ) ) {
    На:
    				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/' ) ) {

Все известные проблемы

Всё ещё сталкиваетесь с этой проблемой?

Если обновление не устраняет проблему, отправьте запрос в поддержку, и мы разберемся в ней вместе с Вами.