Responsive Images: limit the size of images included in `srcset` attributes. Introduce `max_srcset_image_width` filter to adjust the limit.

Props joemcgill.
Fixes #34341.
Built from https://develop.svn.wordpress.org/trunk@35358


git-svn-id: http://core.svn.wordpress.org/trunk@35324 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2015-10-22 19:31:25 +00:00
parent 6ca92efe23
commit dfc2412be1
2 changed files with 15 additions and 1 deletions

View File

@ -928,6 +928,15 @@ function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium'
*/
$img_edited = preg_match( '/-e[0-9]{13}/', $img_url, $img_edit_hash );
/**
* Filter the maximum width included in a srcset attribute.
*
* @since 4.4.0
*
* @param array|string $size Size of image, either array or string.
*/
$max_srcset_width = apply_filters( 'max_srcset_image_width', 1600, $size );
/*
* Set up arrays to hold url candidates and matched image sources so
* we can avoid duplicates without looping through the full sources array
@ -945,6 +954,11 @@ function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium'
continue;
}
// Filter out images that are wider than $max_srcset_width.
if ( $max_srcset_width && $img['width'] > $max_srcset_width ) {
$contiue;
}
$candidate_url = path_join( dirname( $img_url ), $img['file'] );
// Calculate the new image ratio.

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-35357';
$wp_version = '4.4-alpha-35358';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.