WordPress.org

Make WordPress Core

Opened 10 years ago

Closed 8 years ago

Last modified 8 years ago

#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)

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

Download all attachments as: .zip

Change History (10)

@mtdewvirus
10 years ago

#1 @mtdewvirus
10 years ago

  • Version set to 3.1

#2 follow-up: @filosofo
10 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
10 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
10 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
10 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
10 years ago

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

#7 @nacin
9 years ago

  • Keywords reporter-feedback added; attachment image removed

#8 @nickmomrik
8 years ago

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

Unable to reproduce the old problem.

#9 @SergeyBiryukov
8 years ago

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