WordPress.org

Make WordPress Core

Ticket #34477: 34477.2.patch

File 34477.2.patch, 2.9 KB (added by joemcgill, 4 years ago)
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 0ba67a9..87af0dd 100644
    function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa 
    813813
    814814                // Generate 'srcset' and 'sizes' if not already present.
    815815                if ( empty( $attr['srcset'] ) ) {
    816                         $image_meta = wp_get_attachment_metadata( $attachment_id );
     816                        $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
    817817
    818818                        if ( is_array( $image_meta ) ) {
    819819                                $size_array = array( absint( $width ), absint( $height ) );
    820820                                $srcset = wp_calculate_image_srcset( $src, $size_array, $image_meta, $attachment_id );
    821                                 $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id );
     821                                $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id, $src );
    822822
    823823                                if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) {
    824824                                        $attr['srcset'] = $srcset;
    function wp_calculate_image_srcset( $image_name, $size_array, $image_meta, $atta 
    10821082 * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
    10831083 * @param int          $attachment_id Optional. Image attachment ID. Either `$image_meta` or `$attachment_id` is needed
    10841084 *                                    when using the image size name as argument for `$size`.
     1085 * @param string       $image_url     Optional. The URL to the image file.
    10851086 *
    10861087 * @return string|bool A valid source size value for use in a 'sizes' attribute or false.
    10871088 */
    1088 function wp_get_attachment_image_sizes( $size, $image_meta = null, $attachment_id = 0 ) {
     1089function wp_get_attachment_image_sizes( $size, $image_meta = null, $attachment_id = 0, $image_url = null ) {
    10891090        $width = 0;
    10901091
    10911092        if ( is_numeric( $size ) ) {
    function wp_get_attachment_image_sizes( $size, $image_meta = null, $attachment_i 
    11221123         *                                    values in pixels (in that order).
    11231124         * @param array        $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
    11241125         * @param int          $attachment_id Image attachment ID of the original image.
     1126         * @param string       $image_url     Optional. The URL to the image file.
    11251127         */
    1126         return apply_filters( 'wp_get_attachment_image_sizes', $sizes, $size, $image_meta, $attachment_id );
     1128        return apply_filters( 'wp_get_attachment_image_sizes', $sizes, $size, $image_meta, $attachment_id, $image_url );
    11271129}
    11281130
    11291131/**
    function wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ) { 
    12391241        $srcset = wp_calculate_image_srcset( $src, $size_array, $image_meta, $attachment_id );
    12401242
    12411243        if ( $srcset ) {
    1242                 $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id );
     1244                $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id, $src );
    12431245        }
    12441246
    12451247        if ( $srcset && $sizes ) {