Changeset 38296
- Timestamp:
- 08/21/2016 06:14:37 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r38292 r38296 862 862 // Generate 'srcset' and 'sizes' if not already present. 863 863 if ( empty( $attr['srcset'] ) ) { 864 $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true);864 $image_meta = wp_get_attachment_metadata( $attachment_id ); 865 865 866 866 if ( is_array( $image_meta ) ) { … … 991 991 992 992 if ( ! is_array( $image_meta ) ) { 993 $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true);993 $image_meta = wp_get_attachment_metadata( $attachment_id ); 994 994 } 995 995 … … 1207 1207 1208 1208 if ( ! is_array( $image_meta ) ) { 1209 $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true);1209 $image_meta = wp_get_attachment_metadata( $attachment_id ); 1210 1210 } 1211 1211 … … 1240 1240 } elseif ( is_string( $size ) ) { 1241 1241 if ( ! $image_meta && $attachment_id ) { 1242 $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true);1242 $image_meta = wp_get_attachment_metadata( $attachment_id ); 1243 1243 } 1244 1244 … … 1315 1315 1316 1316 foreach ( $selected_images as $image => $attachment_id ) { 1317 $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true);1317 $image_meta = wp_get_attachment_metadata( $attachment_id ); 1318 1318 $content = str_replace( $image, wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ), $content ); 1319 1319 } -
trunk/tests/phpunit/tests/media.php
r38052 r38296 1756 1756 $this->assertSame( $expected, get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ) ); 1757 1757 } 1758 1759 /** 1760 * Tests if wp_get_attachment_image() uses wp_get_attachment_metadata(). 1761 * 1762 * In this way, the meta data can be filtered using the filter 1763 * `wp_get_attachment_metadata`. 1764 * 1765 * The test checks if the image size that is added in the filter is 1766 * used in the output of `wp_get_attachment_image()`. 1767 * 1768 * @ticket 36246 1769 */ 1770 function test_wp_get_attachment_image_should_use_wp_get_attachment_metadata() { 1771 add_filter( 'wp_get_attachment_metadata', array( $this, '_filter_36246' ), 10, 2 ); 1772 1773 $actual = wp_get_attachment_image( self::$large_id, 'testsize' ); 1774 $expected = '<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" srcset="http://example.org/wp-content/uploads/2016/03/test-image-large-150x150.png 150w, http://example.org/wp-content/uploads/2016/03/test-image-testsize-999x999.png 999w" sizes="(max-width: 999px) 100vw, 999px" />'; 1775 1776 remove_filter( 'wp_get_attachment_metadata', array( $this, '_filter_36246' ) ); 1777 1778 $this->assertSame( $expected, $actual ); 1779 } 1780 1781 function _filter_36246( $data, $attachment_id ) { 1782 $data['sizes']['testsize'] = array( 1783 'file' => 'test-image-testsize-999x999.png', 1784 'width' => 999, 1785 'height' => 999, 1786 'mime-type' => 'image/png', 1787 ); 1788 return $data; 1789 } 1758 1790 } 1759 1791
Note: See TracChangeset
for help on using the changeset viewer.