WordPress.org

Make WordPress Core

Changeset 35481


Ignore:
Timestamp:
10/31/2015 10:48:08 PM (4 years ago)
Author:
azaozz
Message:

Responsive images: add $image_url parameter to wp_get_attachment_image_sizes() and use it in the filter. This allows themes and plugins to identify the image.

Props joemcgill.
Fixes #34477.

File:
1 edited

Legend:

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

    r35479 r35481  
    823823        // Generate 'srcset' and 'sizes' if not already present.
    824824        if ( empty( $attr['srcset'] ) ) {
    825             $image_meta = wp_get_attachment_metadata( $attachment_id );
     825            $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
    826826
    827827            if ( is_array( $image_meta ) ) {
    828828                $size_array = array( absint( $width ), absint( $height ) );
    829829                $srcset = wp_calculate_image_srcset( $src, $size_array, $image_meta, $attachment_id );
    830                 $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id );
     830                $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id, $src );
    831831
    832832                if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) {
     
    10921092 * @param int          $attachment_id Optional. Image attachment ID. Either `$image_meta` or `$attachment_id` is needed
    10931093 *                                    when using the image size name as argument for `$size`.
     1094 * @param string       $image_url     Optional. The URL to the image file.
    10941095 *
    10951096 * @return string|bool A valid source size value for use in a 'sizes' attribute or false.
    10961097 */
    1097 function wp_get_attachment_image_sizes( $size, $image_meta = null, $attachment_id = 0 ) {
     1098function wp_get_attachment_image_sizes( $size, $image_meta = null, $attachment_id = 0, $image_url = null ) {
    10981099    $width = 0;
    10991100
     
    11321133     * @param array        $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
    11331134     * @param int          $attachment_id Image attachment ID of the original image.
    1134      */
    1135     return apply_filters( 'wp_get_attachment_image_sizes', $sizes, $size, $image_meta, $attachment_id );
     1135     * @param string       $image_url     Optional. The URL to the image file.
     1136     */
     1137    return apply_filters( 'wp_get_attachment_image_sizes', $sizes, $size, $image_meta, $attachment_id, $image_url );
    11361138}
    11371139
     
    12491251
    12501252    if ( $srcset ) {
    1251         $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id );
     1253        $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id, $src );
    12521254    }
    12531255
Note: See TracChangeset for help on using the changeset viewer.