Make WordPress Core

Ticket #50543: 50543.diff

File 50543.diff, 1.9 KB (added by azaozz, 4 years ago)
  • src/wp-includes/media.php

     
    15081508 *                     or false if dimensions cannot be determined.
    15091509 */
    15101510function wp_image_src_get_dimensions( $image_src, $image_meta ) {
    1511         $image_filename = wp_basename( $image_src );
     1511        // Ensure the $image_meta is for this image. For example the attachment ID used to get the meta
     1512        // may have changed if the site was exported and then imported, etc.
     1513        if ( empty( $image_meta['sizes'] ) || ! isset( $image_meta['file'] ) || strlen( $image_meta['file'] ) < 4 ) {
     1514                return false;
     1515        }
    15121516
    1513         if ( wp_basename( $image_meta['file'] ) === $image_filename ) {
     1517        list( $image_src ) = explode( '?', $image_src );
     1518
     1519        // Match the relative image path inside the uploads directory plus the file name.
     1520        if (
     1521                strpos( $image_src, $image_meta['file'] ) !== false &&
     1522                preg_match( '|' . preg_quote( $image_meta['file'] ) . '$|', $image_src )
     1523        ) {
    15141524                return array(
    15151525                        (int) $image_meta['width'],
    15161526                        (int) $image_meta['height'],
     
    15171527                );
    15181528        }
    15191529
     1530        // Retrieve the uploads sub-directory from the full size image.
     1531        $dirname = _wp_get_attachment_relative_path( $image_meta['file'] );
     1532
     1533        if ( $dirname ) {
     1534                $dirname = trailingslashit( $dirname );
     1535        }
     1536
     1537        $src_filename = wp_basename( $image_src );
     1538
    15201539        foreach ( $image_meta['sizes'] as $image_size_data ) {
    1521                 if ( $image_filename === $image_size_data['file'] ) {
     1540                if (
     1541                        // First check if the filename matches (cheap),
     1542                        // then check if the filename and the relative upload directory is at the end of $image_src.
     1543                        $src_filename === $image_size_data['file'] &&
     1544                        preg_match( '|' . preg_quote( $dirname . $image_size_data['file'] ) . '$|', $image_src )
     1545                ) {
    15221546                        return array(
    15231547                                (int) $image_size_data['width'],
    15241548                                (int) $image_size_data['height'],