Make WordPress Core

Ticket #34124: 34124.2.diff

File 34124.2.diff, 3.8 KB (added by kirasong, 9 years ago)

Add filter to rest of return cases; expand docs.

  • src/wp-includes/media.php

    diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
    index e0ed8f4..9086668 100644
    a b function image_make_intermediate_size( $file, $width, $height, $crop = false ) { 
    600600 * @param int          $post_id Attachment ID.
    601601 * @param array|string $size    Optional. Registered image size to retrieve or flat array of height
    602602 *                              and width dimensions. Default 'thumbnail'.
    603  * @return false|array False on failure or array of file path, width, and height on success.
     603 * @return false|array $data {
     604 *     Array of file relative path, width, and height on success.
     605 *     Additionally includes absolute path and URL if registered size is passed to $size parameter.
     606 *     False on failure.
     607 *
     608 *     @type string $file   Image's path relative to uploads directory
     609 *     @type string $width  Width of image
     610 *     @type string $height Height of image
     611 *     @type string $path   Optional. Image's absolute filesystem path.
     612 *                          Only returned if registered size is passed to $size parameter.
     613 *     @type string $url    Optional. Image's URL.
     614 *                          Only returned if registered size is passed to $size parameter.
     615 * }
    604616 */
    605617function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
    606618        if ( !is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) )
    function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { 
    613625                foreach ( $imagedata['sizes'] as $_size => $data ) {
    614626                        // If there's an exact match to an existing image size, short circuit.
    615627                        if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) {
    616                                 $file = $data['file'];
    617                                 list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
    618                                 return compact( 'file', 'width', 'height' );
     628                                list( $data['width'], $data['height'] ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
     629
     630                                /** This filter is documented in wp-includes/media.php */
     631                                return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
    619632                        }
    620633                        // If it's not an exact match but it's at least the dimensions requested.
    621634                        if ( $data['width'] >= $size[0] && $data['height'] >= $size[1] ) {
    function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { 
    641654                                  continue;
    642655                                }
    643656                                // If we're still here, then we're going to use this size
    644                                 $file = $data['file'];
    645                                 list( $width, $height ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
    646                                 return compact( 'file', 'width', 'height' );
     657                                list( $data['width'], $data['height'] ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
     658
     659                                /** This filter is documented in wp-includes/media.php */
     660                                return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
    647661                        }
    648662                }
    649663        }
    function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { 
    658672                $data['path'] = path_join( dirname($imagedata['file']), $data['file'] );
    659673                $data['url'] = path_join( dirname($file_url), $data['file'] );
    660674        }
    661         return $data;
     675
     676        /**
     677         * Filter the output of image_get_intermediate_size()
     678         *
     679         * @since 4.4.0
     680         *
     681         * @see image_get_intermediate_size()
     682         *
     683         * @param array        $data    Array of file relative path, width, and height on success.
     684         *                              May also include file absolute path and URL. See image_get_intermediate_size() for details.
     685         * @param int          $post_id The post_id of the image attachment
     686         * @param string|array $size    Registered image size or flat array of height and width dimensions initially requested.
     687         */
     688        return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
    662689}
    663690
    664691/**