Make WordPress Core


Ignore:
Timestamp:
10/20/2015 07:23:18 AM (9 years ago)
Author:
DrewAPicture
Message:

Media: Introduce the image_get_intermediate_size filter to its like-named function, making it possible to manipulate returned intermedia image size data.

Covers both the default and meaningful short-circuit return cases. Also adds a hash notation to the return documentation in the DocBlock.

Props A5hleyRich, DH-Shredder, wonderboymusic.
Fixes #34124.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r35250 r35289  
    608608 *                              of width and height values in pixels (in that order).
    609609 *                              Default 'thumbnail'.
    610  * @return false|array False on failure or array of file path, width, and height on success.
     610 * @return false|array $data {
     611 *     Array of file relative path, width, and height on success. Additionally includes absolute
     612 *     path and URL if registered size is passed to $size parameter. False on failure.
     613 *
     614 *     @type string $file   Image's path relative to uploads directory
     615 *     @type int    $width  Width of image
     616 *     @type int    $height Height of image
     617 *     @type string $path   Optional. Image's absolute filesystem path. Only returned if registered
     618 *                          size is passed to `$size` parameter.
     619 *     @type string $url    Optional. Image's URL. Only returned if registered size is passed to `$size`
     620 *                          parameter.
     621 * }
    611622 */
    612623function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
     
    621632            // If there's an exact match to an existing image size, short circuit.
    622633            if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) {
    623                 $file = $data['file'];
    624                 list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
    625                 return compact( 'file', 'width', 'height' );
     634                list( $data['width'], $data['height'] ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
     635
     636                /** This filter is documented in wp-includes/media.php */
     637                return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
    626638            }
    627639            // If it's not an exact match but it's at least the dimensions requested.
     
    648660                  continue;
    649661                }
    650                 // If we're still here, then we're going to use this size
    651                 $file = $data['file'];
    652                 list( $width, $height ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
    653                 return compact( 'file', 'width', 'height' );
     662                // If we're still here, then we're going to use this size.
     663                list( $data['width'], $data['height'] ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
     664
     665                /** This filter is documented in wp-includes/media.php */
     666                return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
    654667            }
    655668        }
     
    666679        $data['url'] = path_join( dirname($file_url), $data['file'] );
    667680    }
    668     return $data;
     681
     682    /**
     683     * Filter the output of image_get_intermediate_size()
     684     *
     685     * @since 4.4.0
     686     *
     687     * @see image_get_intermediate_size()
     688     *
     689     * @param array        $data    Array of file relative path, width, and height on success. May also include
     690     *                              file absolute path and URL.
     691     * @param int          $post_id The post_id of the image attachment
     692     * @param string|array $size    Registered image size or flat array of initially-requested height and width
     693     *                              dimensions (in that order).
     694     */
     695    return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
    669696}
    670697
Note: See TracChangeset for help on using the changeset viewer.