WordPress.org

Make WordPress Core

Ticket #6821: 6821.check-errors.diff

File 6821.check-errors.diff, 2.1 KB (added by markoheijnen, 19 months ago)

Added and fix error checks

  • wp-admin/includes/image-edit.php

    diff --git wp-admin/includes/image-edit.php wp-admin/includes/image-edit.php
    index f390b5e..0b06926 100644
    function wp_save_image( $post_id ) { 
    568568        $post = get_post( $post_id ); 
    569569 
    570570        $img = WP_Image_Editor::get_instance( _load_image_to_edit_path( $post_id, 'full' ) ); 
    571         if ( !$img ) { 
     571        if ( is_wp_error( $img ) ) { 
    572572                $return->error = esc_js( __('Unable to create new image.') ); 
    573573                return $return; 
    574574        } 
  • wp-admin/includes/image.php

    diff --git wp-admin/includes/image.php wp-admin/includes/image.php
    index 2a5123e..01bdbad 100644
    function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_ 
    3333        } 
    3434 
    3535        $editor = WP_Image_Editor::get_instance( $src_file ); 
    36         $src = $editor->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs ); 
     36        if ( is_wp_error( $editor ) ) 
     37                return $editor; 
    3738 
     39        $src = $editor->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs ); 
    3840        if ( is_wp_error( $src ) ) 
    3941                return $src; 
    4042 
    function wp_generate_attachment_metadata( $attachment_id, $file ) { 
    9496                $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes ); 
    9597 
    9698                $editor = WP_Image_Editor::get_instance( $file ); 
    97                 $metadata['sizes'] = $editor->multi_resize( $sizes ); 
     99 
     100                if( ! is_wp_error( $editor ) ) { 
     101                        $metadata['sizes'] = $editor->multi_resize( $sizes ); 
     102                } 
    98103 
    99104                // fetch additional metadata from exif/iptc 
    100105                $image_meta = wp_read_image_metadata( $file ); 
  • wp-includes/media.php

    diff --git wp-includes/media.php wp-includes/media.php
    index 1fc4383..0894e9b 100644
    function image_make_intermediate_size( $file, $width, $height, $crop = false ) { 
    383383        if ( $width || $height ) { 
    384384                $editor = WP_Image_Editor::get_instance( $file ); 
    385385 
    386                 if ( is_wp_error( $editor->resize( $width, $height, $crop ) ) ); 
     386                if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ); 
    387387                        return false; 
    388388 
    389389                $resized_file = $editor->save();