Make WordPress Core

Ticket #34124: 34124.diff

File 34124.diff, 3.6 KB (added by wonderboymusic, 9 years ago)
  • src/wp-includes/media.php

     
    607607 * @param array|string $size    Optional. Image size. Accepts any valid image size, or an array
    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.
     612 *     Additionally includes absolute path and URL if registered size is passed to $size parameter.
     613 *     False on failure.
     614 *
     615 *     @type string $file   Image's path relative to uploads directory
     616 *     @type int    $width  Width of image
     617 *     @type int    $height Height of image
     618 *     @type string $path   Optional. Image's absolute filesystem path.
     619 *                          Only returned if registered size is passed to $size parameter.
     620 *     @type string $url    Optional. Image's URL.
     621 *                          Only returned if registered size is passed to $size parameter.
     622 * }
    611623 */
    612624function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
    613625        if ( !is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) )
     
    620632                foreach ( $imagedata['sizes'] as $_size => $data ) {
    621633                        // If there's an exact match to an existing image size, short circuit.
    622634                        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' );
     635                                list( $data['width'], $data['height'] ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
     636
     637                                /** This filter is documented in wp-includes/media.php */
     638                                return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
    626639                        }
    627640                        // If it's not an exact match but it's at least the dimensions requested.
    628641                        if ( $data['width'] >= $size[0] && $data['height'] >= $size[1] ) {
     
    648661                                  continue;
    649662                                }
    650663                                // 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' );
     664                                list( $data['width'], $data['height'] ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
     665
     666                                /** This filter is documented in wp-includes/media.php */
     667                                return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
    654668                        }
    655669                }
    656670        }
     
    665679                $data['path'] = path_join( dirname($imagedata['file']), $data['file'] );
    666680                $data['url'] = path_join( dirname($file_url), $data['file'] );
    667681        }
    668         return $data;
     682
     683        /**
     684         * Filter the output of image_get_intermediate_size()
     685         *
     686         * @since 4.4.0
     687         *
     688         * @see image_get_intermediate_size()
     689         *
     690         * @param array        $data    Array of file relative path, width, and height on success.
     691         *                              May also include file absolute path and URL. See image_get_intermediate_size() for details.
     692         * @param int          $post_id The post_id of the image attachment
     693         * @param string|array $size    Registered image size or flat array of height and width dimensions initially requested.
     694         */
     695        return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
    669696}
    670697
    671698/**