#36246 closed defect (bug) (fixed)
wp_get_attachment_image should use wp_get_attachment_metadata
Reported by: | JorritSchippers | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | 4.4.2 |
Component: | Media | Keywords: | blessed |
Focuses: | Cc: |
Description
wp_get_attachment_image
uses get_post_meta( $attachment_id, '_wp_attachment_metadata', true )
to fetch attachment meta data, even though the function wp_get_attachment_metadata
does exactly this. This means that the filter wp_get_attachment_metadata
can't be used.
The function wp_get_attachment_image
calls both wp_calculate_image_srcset
and wp_calculate_image_sizes
with the image meta data. These two functions specify that their inputs come from wp_get_attachment_metadata
, but this is not the case in practise.
BTW: media.php contains more situations where get_post_meta( $attachment_id, '_wp_attachment_metadata', true )
could be replaced by wp_get_attachment_metadata($attachment_id)
.
Attachments (3)
Change History (12)
#2
@
9 years ago
- Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
- Milestone changed from Awaiting Review to Future Release
#3
@
8 years ago
- Milestone changed from Future Release to 4.7
- Owner set to wonderboymusic
- Status changed from new to assigned
#5
@
8 years ago
- Keywords has-patch has-unit-tests removed
- Resolution fixed deleted
- Status changed from closed to reopened
The unit tests for this are failing.
1) Tests_Media::test_wp_get_attachment_image_should_use_wp_get_attachment_metadata Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -<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" /> +<img width="999" height="999" src="http://example.org/wp-content/uploads/2016/08/test-image-testsize-999x999.png" class="attachment-testsize size-testsize" alt="test-image-large.png" srcset="http://example.org/wp-content/uploads/2016/08/test-image-testsize-999x999.png 999w, http://example.org/wp-content/uploads/2016/08/test-image-large-150x150.png 150w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" />
Note: See
TracTickets for help on using
tickets.
patch with test