Make WordPress Core


Ignore:
Timestamp:
07/12/2020 09:18:38 PM (4 years ago)
Author:
azaozz
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r48430 r48454  
    15231523        if ( strrpos( $image_location, $image_meta['file'] ) === strlen( $image_location ) - strlen( $image_meta['file'] ) ) {
    15241524            $match = true;
    1525         } elseif ( ! empty( $image_meta['sizes'] ) ) {
     1525        } else {
    15261526            // Retrieve the uploads sub-directory from the full size image.
    15271527            $dirname = _wp_get_attachment_relative_path( $image_meta['file'] );
     
    15311531            }
    15321532
    1533             foreach ( $image_meta['sizes'] as $image_size_data ) {
    1534                 $relative_path = $dirname . $image_size_data['file'];
     1533            if ( ! empty( $image_meta['original_image'] ) ) {
     1534                $relative_path = $dirname . $image_meta['original_image'];
    15351535
    15361536                if ( strrpos( $image_location, $relative_path ) === strlen( $image_location ) - strlen( $relative_path ) ) {
    15371537                    $match = true;
    1538                     break;
     1538                }
     1539            }
     1540
     1541            if ( ! $match && ! empty( $image_meta['sizes'] ) ) {
     1542                foreach ( $image_meta['sizes'] as $image_size_data ) {
     1543                    $relative_path = $dirname . $image_size_data['file'];
     1544
     1545                    if ( strrpos( $image_location, $relative_path ) === strlen( $image_location ) - strlen( $relative_path ) ) {
     1546                        $match = true;
     1547                        break;
     1548                    }
    15391549                }
    15401550            }
Note: See TracChangeset for help on using the changeset viewer.