From 8529c19a8d40f5d4d9bfdfa7abc6991b132e2eec Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Mon, 7 Dec 2015 20:29:26 +0000 Subject: [PATCH] Media: Don't generate responsive image attributes if `src` does not match ID in `wp-image-` class. We rely on the `wp-image-` class to quickly find an attachment ID to add responsive image attributes. To avoid incorrect images being displayed, do not add these attributes if the `src` does not match the meta from the attachment ID in the class. Merge of [35820] to the 4.4 branch. Props azaozz, kovshenin, joemcgill, mikeschroder. See #34898. Built from https://develop.svn.wordpress.org/branches/4.4@35821 git-svn-id: http://core.svn.wordpress.org/branches/4.4@35785 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 22 ++++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index ddd7088a1d..e6c27b0c85 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1278,6 +1278,28 @@ function wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ) { return $image; } + $base_url = trailingslashit( _wp_upload_dir_baseurl() ); + $image_base_url = $base_url; + + $dirname = dirname( $image_meta['file'] ); + if ( $dirname !== '.' ) { + $image_base_url .= trailingslashit( $dirname ); + } + + $all_sizes = wp_list_pluck( $image_meta['sizes'], 'file' ); + + foreach ( $all_sizes as $key => $file ) { + $all_sizes[ $key ] = $image_base_url . $file; + } + + // Add the original image. + $all_sizes[] = $base_url . $image_meta['file']; + + // Bail early if the image src doesn't match any of the known image sizes. + if ( ! in_array( $image_src, $all_sizes ) ) { + return $image; + } + $width = preg_match( '/ width="([0-9]+)"/', $image, $match_width ) ? (int) $match_width[1] : 0; $height = preg_match( '/ height="([0-9]+)"/', $image, $match_height ) ? (int) $match_height[1] : 0; diff --git a/wp-includes/version.php b/wp-includes/version.php index 9cf4114e94..15474accb8 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-RC1-35819'; +$wp_version = '4.4-RC1-35821'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.