WordPress.org

Make WordPress Core

Ticket #9922: 9922.diff

File 9922.diff, 2.8 KB (added by mdawaffe, 5 years ago)
  • wp-includes/media.php

     
    334334 
    335335        $image = wp_load_image( $file ); 
    336336        if ( !is_resource( $image ) ) 
    337                 return new WP_Error('error_loading_image', $image); 
     337                return new WP_Error( 'error_loading_image', $image, $file ); 
    338338 
    339339        list($orig_w, $orig_h, $orig_type) = getimagesize( $file ); 
    340340        $dims = image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop); 
  • wp-admin/includes/image.php

     
    3838 * @param int $dst_h The destination height. 
    3939 * @param int $src_abs Optional. If the source crop points are absolute. 
    4040 * @param string $dst_file Optional. The destination file to write to. 
    41  * @return string New filepath on success, String error message on failure. 
     41 * @return string|WP_Error|false New filepath on success, WP_Error or false on failure. 
    4242 */ 
    4343function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) { 
    4444        if ( is_numeric( $src_file ) ) // Handle int as attachment ID 
     
    4646 
    4747        $src = wp_load_image( $src_file ); 
    4848 
    49         if ( !is_resource( $src )) 
    50                 return $src; 
     49        if ( !is_resource( $src ) ) 
     50                return new WP_Error( 'error_loading_image', $src, $src_file ); 
    5151 
    5252        $dst = imagecreatetruecolor( $dst_w, $dst_h ); 
    5353 
  • wp-admin/custom-header.php

     
    360360                } elseif ( $width > HEADER_IMAGE_WIDTH ) { 
    361361                        $oitar = $width / HEADER_IMAGE_WIDTH; 
    362362                        $image = wp_crop_image($file, 0, 0, $width, $height, HEADER_IMAGE_WIDTH, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file)); 
     363                        if ( is_wp_error( $image ) ) 
     364                                wp_die( __( 'Image could not be processed.  Please go back and try again.' ), __( 'Image Processing Error' ) ); 
     365 
    363366                        $image = apply_filters('wp_create_file_in_uploads', $image, $id); // For replication 
    364367 
    365368                        $url = str_replace(basename($url), basename($image), $url); 
     
    414417                $original = get_attached_file( $_POST['attachment_id'] ); 
    415418 
    416419                $cropped = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); 
     420                if ( is_wp_error( $cropped ) ) 
     421                        wp_die( __( 'Image could not be processed.  Please go back and try again.' ), __( 'Image Processing Error' ) ); 
     422 
    417423                $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $_POST['attachment_id']); // For replication 
    418424 
    419425                $parent = get_post($_POST['attachment_id']);