WordPress.org

Make WordPress Core

Ticket #34477: 34477.patch

File 34477.patch, 1.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 17af247..1d4a3f2 100644
    function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa 
    818818                        if ( is_array( $image_meta ) ) {
    819819                                $size_array = array( absint( $width ), absint( $height ) );
    820820                                $sources    = 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, $image_meta, $attachment_id );
    822822
    823823                                if ( count( $sources ) > 1 && ( $sizes || ! empty( $attr['sizes'] ) ) ) {
    824824                                        $attr['srcset'] = wp_image_srcset_attr( $sources, $size_array, $image_meta, $attachment_id );
  • tests/phpunit/tests/media.php

    diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php
    index 3a71bd2..5a51c8b 100644
    EOF; 
    926926        /**
    927927         * @ticket 33641
    928928         */
     929        function test_wp_get_attachment_image_with_sizes_named_filter() {
     930                add_filter( 'wp_get_attachment_image_sizes', array( $this, '_filter_attachment_image_sizes_named_size' ), 10, 4 );
     931
     932                $image = wp_get_attachment_image( self::$large_id, 'large' );
     933                $srcset = '(max-width: 600px) 80vw, 600px';
     934
     935                $this->assertTrue( strrpos( $image, $srcset ) > 0 );
     936
     937                //cleanup
     938                remove_filter( 'wp_get_attachment_image_sizes', array( $this, '_filter_attachment_image_sizes_named_size' ) );
     939        }
     940
     941        // Example filter
     942        function _filter_attachment_image_sizes_named_size( $sizes, $size, $image_meta, $attachment_id ) {
     943                if ( $size === 'large' ) {
     944                        $sizes = '(max-width: 600px) 80vw, 600px';
     945                }
     946
     947                return $sizes;
     948        }
     949
     950        /**
     951         * @ticket 33641
     952         */
    929953        function test_wp_make_content_images_responsive() {
    930954                $image_meta = wp_get_attachment_metadata( self::$large_id );
    931955                $size_array = $this->_get_image_size_array_from_name( 'medium' );