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
This commit is contained in:
Andrew Ozz 2020-07-12 21:20:03 +00:00
parent 63a2cb3060
commit 618c32686e
2 changed files with 15 additions and 5 deletions

View File

@ -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;
}
}
}
}

View File

@ -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.