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.


git-svn-id: https://develop.svn.wordpress.org/branches/4.4@36150 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2016-01-02 03:52:01 +00:00
parent 641ae4f39f
commit 750a86d2f9
2 changed files with 52 additions and 2 deletions

View File

@ -1049,8 +1049,13 @@ function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac
continue;
}
// Filter out images that are wider than '$max_srcset_image_width'.
if ( $max_srcset_image_width && $image['width'] > $max_srcset_image_width ) {
/*
* Filter out images that are wider than '$max_srcset_image_width' unless
* that file is in the 'src' attribute.
*/
if ( $max_srcset_image_width && $image['width'] > $max_srcset_image_width &&
false === strpos( $image_src, $image['file'] ) ) {
continue;
}

View File

@ -891,6 +891,51 @@ EOF;
$this->assertFalse( $srcset );
}
/**
* @ticket 35108
* @ticket 33641
*/
function test_wp_calculate_image_srcset_include_src() {
// Mock data for this test.
$size_array = array( 2000, 1000 );
$image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png';
$image_meta = array(
'width' => 2000,
'height' => 1000,
'file' => '2015/12/test.png',
'sizes' => array(
'thumbnail' => array(
'file' => 'test-150x150.png',
'width' => 150,
'height' => 150,
'mime-type' => 'image/png',
),
'medium' => array(
'file' => 'test-300x150.png',
'width' => 300,
'height' => 150,
'mime-type' => 'image/png',
),
'medium_large' => array(
'file' => 'test-768x384.png',
'width' => 768,
'height' => 384,
'mime-type' => 'image/png',
),
'large' => array(
'file' => 'test-1024x512.png',
'width' => 1024,
'height' => 512,
'mime-type' => 'image/png',
),
),
);
$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';
$this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_src, $image_meta ) );
}
/**
* @ticket 33641
*/