Make WordPress Core

Changeset 36110


Ignore:
Timestamp:
12/28/2015 02:28:53 AM (11 years ago)
Author:
azaozz
Message:

Responsive images: when creating srcset do not exclude the image size which is in the src attribute even when it is larger than max_srcset_image_width.

Props joemcgill.
Fixes #35108 for trunk.

Location:
trunk
Files:
2 edited

Legend:

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

    r36031 r36110  
    10471047                }
    10481048
    1049                 // Filter out images that are wider than '$max_srcset_image_width'.
    1050                 if ( $max_srcset_image_width && $image['width'] > $max_srcset_image_width ) {
     1049                /*
     1050                 * Filter out images that are wider than '$max_srcset_image_width' unless
     1051                 * that file is in the 'src' attribute.
     1052                 */
     1053                if ( $max_srcset_image_width && $image['width'] > $max_srcset_image_width &&
     1054                        false === strpos( $image_src, $image['file'] ) ) {
     1055
    10511056                        continue;
    10521057                }
  • trunk/tests/phpunit/tests/media.php

    r36031 r36110  
    894894        /**
    895895         * @ticket 34955
     896         * @ticket 33641
    896897         */
    897898        function test_wp_calculate_image_srcset_ratio_variance() {
    898899                // Mock data for this test.
    899                 $size_array = array( 218, 300);
     900                $size_array = array( 218, 300 );
    900901                $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-768x1055-218x300.png';
    901902                $image_meta = array(
     
    937938
    938939        /**
     940         * @ticket 35108
     941         * @ticket 33641
     942         */
     943        function test_wp_calculate_image_srcset_include_src() {
     944                // Mock data for this test.
     945                $size_array = array( 2000, 1000 );
     946                $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png';
     947                $image_meta = array(
     948                        'width' => 2000,
     949                        'height' => 1000,
     950                        'file' => '2015/12/test.png',
     951                        'sizes' => array(
     952                                'thumbnail' => array(
     953                                        'file' => 'test-150x150.png',
     954                                        'width' => 150,
     955                                        'height' => 150,
     956                                        'mime-type' => 'image/png',
     957                                ),
     958                                'medium' => array(
     959                                        'file' => 'test-300x150.png',
     960                                        'width' => 300,
     961                                        'height' => 150,
     962                                        'mime-type' => 'image/png',
     963                                ),
     964                                'medium_large' => array(
     965                                        'file' => 'test-768x384.png',
     966                                        'width' => 768,
     967                                        'height' => 384,
     968                                        'mime-type' => 'image/png',
     969                                ),
     970                                'large' => array(
     971                                        'file' => 'test-1024x512.png',
     972                                        'width' => 1024,
     973                                        'height' => 512,
     974                                        'mime-type' => 'image/png',
     975                                ),
     976                        ),
     977                );
     978
     979                $expected_srcset = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-300x150.png 300w, http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-768x384.png 768w, http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-1024x512.png 1024w, http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png 2000w';
     980
     981                $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_src, $image_meta ) );
     982        }
     983
     984        /**
    939985         * @ticket 33641
    940986         */
Note: See TracChangeset for help on using the changeset viewer.