Ticket #50543: 50543.1.diff
File 50543.1.diff, 1.9 KB (added by , 4 years ago) |
---|
-
src/wp-includes/media.php
1508 1508 * or false if dimensions cannot be determined. 1509 1509 */ 1510 1510 function 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 ( ! isset( $image_meta['file'] ) || strlen( $image_meta['file'] ) < 4 ) { 1514 return false; 1515 } 1512 1516 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 ) { 1514 1524 return array( 1515 1525 (int) $image_meta['width'], 1516 1526 (int) $image_meta['height'], … … 1517 1527 ); 1518 1528 } 1519 1529 1530 if ( empty( $image_meta['sizes'] ) ) { 1531 return false; 1532 } 1533 1534 // Retrieve the uploads sub-directory from the full size image. 1535 $dirname = _wp_get_attachment_relative_path( $image_meta['file'] ); 1536 1537 if ( $dirname ) { 1538 $dirname = trailingslashit( $dirname ); 1539 } 1540 1541 $src_filename = wp_basename( $image_src ); 1542 1520 1543 foreach ( $image_meta['sizes'] as $image_size_data ) { 1521 if ( $image_filename === $image_size_data['file'] ) { 1544 if ( 1545 // First check if the filename matches (cheap), 1546 // then check if the filename and the relative upload directory is at the end of $image_src. 1547 $src_filename === $image_size_data['file'] && 1548 preg_match( '|' . preg_quote( $dirname . $image_size_data['file'] ) . '$|', $image_src ) 1549 ) { 1522 1550 return array( 1523 1551 (int) $image_size_data['width'], 1524 1552 (int) $image_size_data['height'],