Make WordPress Core

Ticket #24717: Get-custom-image-size-from-a-global-object.patch

File Get-custom-image-size-from-a-global-object.patch, 2.0 KB (added by Fab1en, 11 years ago)

Proposed correction patch

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

    From: Fabien Quatravaux <fabien.quatravaux@1nterval.com>
    Date: Tue, 9 Jul 2013 11:55:59 +0200
    Subject: [PATCH] [fix CORE #24717] Get custom image size from a global object
    
    In the Media Library, images can be edited directly in WP : you can crop them,
    rotate and so on. You can also decide to apply changes to the main image only,
    the thumbnails only or to all sizes.
    But even when applied to all sizes, only thumbnail, medium and large size are
    updated. Size added via add_image_size are not changed.
    
    I thought this was a feature to implement, but when digging in the code, I saw
    that the custom image sizes are taken care of. There is just a small bug that
    prevents the sizes to be set correctly, hence the resizing process fails for
    those sizes.
    
    Additionnal image sizes are not stored in database but in a global object.
    ---
     wp-admin/includes/image-edit.php |   13 ++++++++++++-
     1 file changed, 12 insertions(+), 1 deletion(-)
    
    diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php
    index 01bce7b..06bd7ee 100644
    a b function wp_save_image( $post_id ) { 
    690690
    691691                        $crop = $nocrop ? false : get_option("{$size}_crop");
    692692                        $_sizes[ $size ] = array( 'width' => get_option("{$size}_size_w"), 'height' => get_option("{$size}_size_h"), 'crop' => $crop );
     693                       
     694                        // bugfix #24717
     695                        // additionnal image sizes are not stored in database but in a global object
     696                        global $_wp_additional_image_sizes;
     697                        if( isset( $_wp_additional_image_sizes[$size] ) ) {
     698                                if( empty( $_sizes[ $size ]['width'] ) && isset( $_wp_additional_image_sizes[$size]['width'] ) ) {
     699                                        $_sizes[ $size ]['width'] = $_wp_additional_image_sizes[$size]['width'];
     700                                }
     701                                if( empty( $_sizes[ $size ]['height'] ) && isset( $_wp_additional_image_sizes[$size]['height'] ) ) {
     702                                        $_sizes[ $size ]['height'] = $_wp_additional_image_sizes[$size]['height'];
     703                                }
     704                        }
    693705                }
    694 
    695706                $meta['sizes'] = array_merge( $meta['sizes'], $img->multi_resize( $_sizes ) );
    696707        }
    697708