WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/27/2014 08:39:08 PM (8 years ago)
Author:
wonderboymusic
Message:

In multi_resize() image editor methods, assert that null can only be passed for one of the arguments, not both. Add a lot more unit test assertions to ensure this.

Props pbearne, DH-Shredder.
Fixes #26823.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-image-editor-gd.php

    r26851 r27794  
    141141     * Wraps _resize, since _resize returns a GD Resource.
    142142     *
    143      * @since 3.5.0
    144      * @access public
    145      *
    146      * @param int $max_w
    147      * @param int $max_h
    148      * @param boolean $crop
     143     * At minimum, either a height or width must be provided.
     144     * If one of the two is set to null, the resize will
     145     * maintain aspect ratio according to the provided dimension.
     146     *
     147     * @since 3.5.0
     148     * @access public
     149     *
     150     * @param  int|null $max_w Image width.
     151     * @param  int|null $max_h Image height.
     152     * @param  boolean  $crop
    149153     * @return boolean|WP_Error
    150154     */
     
    193197     *     An array of image size arrays. Default sizes are 'small', 'medium', 'large'.
    194198     *
     199     *     Either a height or width must be provided.
     200     *     If one of the two is set to null, the resize will
     201     *     maintain aspect ratio according to the provided dimension.
     202     *
    195203     *     @type array $size {
    196      *         @type int  $width Image width.
    197      *         @type int  $height Image height.
    198      *         @type bool $crop   Optional. Whether to crop the image. Default false.
     204     *         @type int  ['width']  Optional. Image width.
     205     *         @type int  ['height'] Optional. Image height.
     206     *         @type bool ['crop']   Optional. Whether to crop the image. Default false.
    199207     *     }
    200208     * }
    201      * @return array An array of resized images metadata by size.
     209     * @return array An array of resized images' metadata by size.
    202210     */
    203211    public function multi_resize( $sizes ) {
     
    206214
    207215        foreach ( $sizes as $size => $size_data ) {
    208             if ( ! ( isset( $size_data['width'] ) && isset( $size_data['height'] ) ) )
     216            if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) {
    209217                continue;
    210 
    211             if ( ! isset( $size_data['crop'] ) )
     218            }
     219
     220            if ( ! isset( $size_data['width'] ) ) {
     221                $size_data['width'] = null;
     222            }
     223            if ( ! isset( $size_data['height'] ) ) {
     224                $size_data['height'] = null;
     225            }
     226
     227            if ( ! isset( $size_data['crop'] ) ) {
    212228                $size_data['crop'] = false;
     229            }
    213230
    214231            $image = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'] );
Note: See TracChangeset for help on using the changeset viewer.