WPML

Panoramica del problema

Se utilizzi l’hosting Flywheel o ImageMagick, caricare un PDF nella tua libreria di WordPress genera un errore fatale:

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

Soluzione alternativa

Questo problema è stato risolto in WPML 4.6.4. L'aggiornamento risolve il problema sul tuo sito, quindi hai bisogno di questa soluzione alternativa solo se non puoi ancora aggiornare.

  1. Fai un backup completo del tuo sito.
  2. Modifica /wp-content/plugins/wpml-media-translation/classes/media-translation/class-wpml-media-attachment-image-update.php, righe 49-76
  3. Cambia:
    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/' ) ) {
    in:
    				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/' ) ) {

Tutti i problemi noti

Riscontri ancora questo problema?

Se l’aggiornamento non risolve il problema, fai una richiesta di supporto e lo analizzeremo con te.