Ticket #36246: 36246-attachment-metadata.patch
File 36246-attachment-metadata.patch, 3.6 KB (added by , 9 years ago) |
---|
-
src/wp-includes/media.php
diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 7b99f95..83b6979 100644
a b function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa 822 822 823 823 // Generate 'srcset' and 'sizes' if not already present. 824 824 if ( empty( $attr['srcset'] ) ) { 825 $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true);825 $image_meta = wp_get_attachment_metadata( $attachment_id ); 826 826 827 827 if ( is_array( $image_meta ) ) { 828 828 $size_array = array( absint( $width ), absint( $height ) ); … … function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $imag 951 951 } 952 952 953 953 if ( ! is_array( $image_meta ) ) { 954 $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true);954 $image_meta = wp_get_attachment_metadata( $attachment_id ); 955 955 } 956 956 957 957 $image_src = $image[0]; … … function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image 1166 1166 } 1167 1167 1168 1168 if ( ! is_array( $image_meta ) ) { 1169 $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true);1169 $image_meta = wp_get_attachment_metadata( $attachment_id ); 1170 1170 } 1171 1171 1172 1172 $image_src = $image[0]; … … function wp_calculate_image_sizes( $size, $image_src = null, $image_meta = null, 1199 1199 $width = absint( $size[0] ); 1200 1200 } elseif ( is_string( $size ) ) { 1201 1201 if ( ! $image_meta && $attachment_id ) { 1202 $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true);1202 $image_meta = wp_get_attachment_metadata( $attachment_id ); 1203 1203 } 1204 1204 1205 1205 if ( is_array( $image_meta ) ) { … … function wp_make_content_images_responsive( $content ) { 1274 1274 } 1275 1275 1276 1276 foreach ( $selected_images as $image => $attachment_id ) { 1277 $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true);1277 $image_meta = wp_get_attachment_metadata( $attachment_id ); 1278 1278 $content = str_replace( $image, wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ), $content ); 1279 1279 } 1280 1280 -
tests/phpunit/tests/media.php
diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 5399f85..56cd19c 100644
a b EOF; 1476 1476 1477 1477 $this->assertSame( $expected, $actual ); 1478 1478 } 1479 1480 /** 1481 * Tests if wp_get_attachment_image() uses wp_get_attachment_metadata(). 1482 * 1483 * In this way, the meta data can be filtered using the filter 1484 * `wp_get_attachment_metadata`. 1485 * 1486 * The test checks if the image size that is added in the filter is 1487 * used in the output of `wp_get_attachment_image()`. 1488 * 1489 * @ticket 36246 1490 */ 1491 function test_wp_get_attachment_image_should_use_wp_get_attachment_metadata() { 1492 add_filter( 'wp_get_attachment_metadata', array($this, 'filter_test_wp_get_attachment_image_should_use_wp_get_attachment_metadata'), 10, 2 ); 1493 1494 $actual = wp_get_attachment_image( self::$large_id, 'testsize' ); 1495 $expeced = '<img width="999" height="999" src="http://example.org/wp-content/uploads/2016/03/test-image-testsize-999x999.png" class="attachment-testsize size-testsize" alt="test-image-large.png" />'; 1496 1497 remove_filter( 'wp_get_attachment_metadata', array($this, 'filter_test_wp_get_attachment_image_should_use_wp_get_attachment_metadata') ); 1498 } 1499 1500 function filter_test_wp_get_attachment_image_should_use_wp_get_attachment_metadata($data, $attachment_id) { 1501 $data['sizes']['testsize'] = array( 1502 'file' => 'test-image-testsize-999x999.png', 1503 'width' => 999, 1504 'height' => 999, 1505 'mime-type' => 'image/png', 1506 ); 1507 return $data; 1508 } 1479 1509 }