WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 11 months ago

Last modified 11 months ago

#15614 closed defect (bug) (invalid)

wp_get_attachment_image functions should check id for an image

Reported by: mtdewvirus Owned by:
Priority: normal Milestone:
Component: Media Version: 3.1
Severity: normal Keywords: reporter-feedback
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 3 years ago.

Download all attachments as: .zip

Change History (10)

mtdewvirus3 years ago

comment:1 mtdewvirus3 years ago

  • Version set to 3.1

comment:2 follow-up: filosofo3 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.

comment:3 in reply to: ↑ 2 mtdewvirus3 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.

comment:4 follow-up: filosofo3 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.

comment:5 in reply to: ↑ 4 mtdewvirus3 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.

comment:6 scribu3 years ago

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

comment:7 nacin2 years ago

  • Keywords reporter-feedback added; attachment image removed

comment:8 nickmomrik11 months ago

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

Unable to reproduce the old problem.

comment:9 SergeyBiryukov11 months ago

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