Make WordPress Core

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#15614 closed defect (bug) (invalid)

wp_get_attachment_image functions should check id for an image

Reported by: mtdewvirus's profile 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)

15614.diff (1.1 KB) - added by mtdewvirus 13 years ago.

Download all attachments as: .zip

Change History (10)

@mtdewvirus
13 years ago

#1 @mtdewvirus
13 years ago

  • Version set to 3.1

#2 follow-up: @filosofo
13 years ago

What are the unexpected results? wp_get_attachment_image calls wp_get_attachment_image_src, which calls image_downsize, and image_downsize performs that check already. I don't see how you would get anything other than an empty string or false already.

#3 in reply to: ↑ 2 @mtdewvirus
13 years ago

Replying to filosofo:

What are the unexpected results? wp_get_attachment_image calls wp_get_attachment_image_src, which calls image_downsize, and image_downsize performs that check already. I don't see how you would get anything other than an empty string or false 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: @filosofo
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 @mtdewvirus
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.

#6 @scribu
13 years ago

Please either show us the code, or give us exact steps to reproduce.

#7 @nacin
13 years ago

  • Keywords reporter-feedback added; attachment image removed

#8 @nickmomrik
12 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Unable to reproduce the old problem.

#9 @SergeyBiryukov
12 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.