From dfc2412be1d65391f4b17319a90fca3358157cb1 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 22 Oct 2015 19:31:25 +0000 Subject: [PATCH] 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 --- wp-includes/media.php | 14 ++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index 210bf425c9..de1f2c480d 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -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. diff --git a/wp-includes/version.php b/wp-includes/version.php index e7572a7cda..49d2acc2c6 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.