From 618c32686e7d1eec396df68250aa7cfc8bfbb891 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sun, 12 Jul 2020 21:20:03 +0000 Subject: [PATCH] Media: Fix `wp_image_file_matches_image_meta()` to also match when the original image URL is used. Also refreshes and fixes some of the unit tests for media, and replaces test-image-large.png with test-image-large.jpg which is larger to allow testing of `original_image` in the image meta. Fixes #50628. Built from https://develop.svn.wordpress.org/trunk@48454 git-svn-id: http://core.svn.wordpress.org/trunk@48223 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 18 ++++++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index d316f1a6f3..4f1eed831f 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1522,7 +1522,7 @@ function wp_image_file_matches_image_meta( $image_location, $image_meta ) { // Check if the relative image path from the image meta is at the end of $image_location. if ( strrpos( $image_location, $image_meta['file'] ) === strlen( $image_location ) - strlen( $image_meta['file'] ) ) { $match = true; - } elseif ( ! empty( $image_meta['sizes'] ) ) { + } else { // Retrieve the uploads sub-directory from the full size image. $dirname = _wp_get_attachment_relative_path( $image_meta['file'] ); @@ -1530,12 +1530,22 @@ function wp_image_file_matches_image_meta( $image_location, $image_meta ) { $dirname = trailingslashit( $dirname ); } - foreach ( $image_meta['sizes'] as $image_size_data ) { - $relative_path = $dirname . $image_size_data['file']; + if ( ! empty( $image_meta['original_image'] ) ) { + $relative_path = $dirname . $image_meta['original_image']; if ( strrpos( $image_location, $relative_path ) === strlen( $image_location ) - strlen( $relative_path ) ) { $match = true; - break; + } + } + + if ( ! $match && ! empty( $image_meta['sizes'] ) ) { + foreach ( $image_meta['sizes'] as $image_size_data ) { + $relative_path = $dirname . $image_size_data['file']; + + if ( strrpos( $image_location, $relative_path ) === strlen( $image_location ) - strlen( $relative_path ) ) { + $match = true; + break; + } } } } diff --git a/wp-includes/version.php b/wp-includes/version.php index b4da099b64..d850776b14 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-beta1-48453'; +$wp_version = '5.5-beta1-48454'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.