#15614 closed defect (bug) (invalid)
wp_get_attachment_image functions should check id for an image
Reported by: | mtdewvirus | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.1 |
Component: | Media | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
The wp_get_attachment_image() and wp_get_attachment_image_src() functions do not check to be sure the post_id is an attachment image. Running these functions on ids that are not images produces unexpected results. Attached patch adds a check for wp_attachment_is_image() to the top of each function.
Attachments (1)
Change History (10)
#3
in reply to:
↑ 2
@
13 years ago
Replying to filosofo:
What are the unexpected results?
wp_get_attachment_image
callswp_get_attachment_image_src
, which callsimage_downsize
, andimage_downsize
performs that check already. I don't see how you would get anything other than an empty string orfalse
already.
Run it on a video post_id and you get an image returned. If image_downsize
fails in wp_get_attachment_image_src
, the function still tries to get an image by using wp_mime_type_icon
.
#4
follow-up:
↓ 5
@
13 years ago
Isn't that the correct behavior, though? You have to be requesting the icon in particular, which might exist for the video object.
#5
in reply to:
↑ 4
@
13 years ago
Replying to filosofo:
Isn't that the correct behavior, though? You have to be requesting the icon in particular, which might exist for the video object.
The param for both functions should be an image attachment id:
@param int $attachment_id Image attachment ID
In my testing, the returned image has nothing to do with the video. It returns a completely different attachment from the Media Library.
What are the unexpected results?
wp_get_attachment_image
callswp_get_attachment_image_src
, which callsimage_downsize
, andimage_downsize
performs that check already. I don't see how you would get anything other than an empty string orfalse
already.