Make WordPress Core

Changeset 36150


Ignore:
Timestamp:
01/02/2016 03:52:01 AM (11 years ago)
Author:
dd32
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.

Merges [36110] to the 4.4 branch.
Props joemcgill.
Fixes #35108.

Location:
branches/4.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4

  • branches/4.4/src/wp-includes/media.php

    r35821 r36150  
    10501050                }
    10511051
    1052                 // Filter out images that are wider than '$max_srcset_image_width'.
    1053                 if ( $max_srcset_image_width && $image['width'] > $max_srcset_image_width ) {
     1052                /*
     1053                 * Filter out images that are wider than '$max_srcset_image_width' unless
     1054                 * that file is in the 'src' attribute.
     1055                 */
     1056                if ( $max_srcset_image_width && $image['width'] > $max_srcset_image_width &&
     1057                        false === strpos( $image_src, $image['file'] ) ) {
     1058
    10541059                        continue;
    10551060                }
  • branches/4.4/tests/phpunit/tests/media.php

    r35821 r36150  
    890890                // The srcset should be false.
    891891                $this->assertFalse( $srcset );
     892        }
     893
     894        /**
     895         * @ticket 35108
     896         * @ticket 33641
     897         */
     898        function test_wp_calculate_image_srcset_include_src() {
     899                // Mock data for this test.
     900                $size_array = array( 2000, 1000 );
     901                $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png';
     902                $image_meta = array(
     903                        'width' => 2000,
     904                        'height' => 1000,
     905                        'file' => '2015/12/test.png',
     906                        'sizes' => array(
     907                                'thumbnail' => array(
     908                                        'file' => 'test-150x150.png',
     909                                        'width' => 150,
     910                                        'height' => 150,
     911                                        'mime-type' => 'image/png',
     912                                ),
     913                                'medium' => array(
     914                                        'file' => 'test-300x150.png',
     915                                        'width' => 300,
     916                                        'height' => 150,
     917                                        'mime-type' => 'image/png',
     918                                ),
     919                                'medium_large' => array(
     920                                        'file' => 'test-768x384.png',
     921                                        'width' => 768,
     922                                        'height' => 384,
     923                                        'mime-type' => 'image/png',
     924                                ),
     925                                'large' => array(
     926                                        'file' => 'test-1024x512.png',
     927                                        'width' => 1024,
     928                                        'height' => 512,
     929                                        'mime-type' => 'image/png',
     930                                ),
     931                        ),
     932                );
     933
     934                $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';
     935
     936                $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_src, $image_meta ) );
    892937        }
    893938
Note: See TracChangeset for help on using the changeset viewer.