WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#33959 new enhancement

Improve wp_get_attachment_thumb_file

Reported by: Rahe Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.4
Component: Media Keywords: has-patch needs-refresh needs-unit-tests
Focuses: Cc:

Description

Since we can retrieve an image thumbnail url it will be nice if we can get the path of this thumbnail too.

Here is a patch allowing this. And improvements for the first parameter allowing it to be a WP_Post object.

Attachments (2)

33959.diff (2.4 KB) - added by Rahe 2 years ago.
33959.2.diff (1.8 KB) - added by Rahe 2 years ago.
V2

Download all attachments as: .zip

Change History (8)

@Rahe
2 years ago

#1 @swissspidy
2 years ago

  • Component changed from Post Thumbnails to Media
  • Keywords has-patch needs-refresh needs-unit-tests added

I'd rather introduce a new wp_get_attachment_file( $post, $size ) function. wp_get_attachment_thumb_file() could then simply be a wrapper for wp_get_attachment_file( $post = null, $size = 'thumb' )

@Rahe
2 years ago

V2

#2 @Rahe
2 years ago

Here one another patch with the suggested modifications.
I don't know how to create the unit test for it, but i'd like to do so :)

#3 follow-ups: @swissspidy
2 years ago

Just had another look at this.

First of all, it seems like wp_get_attachment_thumb_file doesn't even work. $imagedata['thumb'] should probably be $imagedata['sizes']['thumbnail']['file']. See also this bug report from 3 years ago.
Second, doesn't image_get_intermediate_size already do what you want to achieve?

This ticket was mentioned in Slack in #core by swissspidy. View the logs.


2 years ago

#5 in reply to: ↑ 3 @SergeyBiryukov
2 years ago

Replying to swissspidy:

First of all, it seems like wp_get_attachment_thumb_file doesn't even work. $imagedata['thumb'] should probably be $imagedata['sizes']['thumbnail']['file'].

See #17262.

#6 in reply to: ↑ 3 @joemcgill
2 years ago

Replying to swissspidy:

Second, doesn't image_get_intermediate_size already do what you want to achieve?

The documentation for image_get_intermediate_size isn't clear (see: #34124), but you're correct that it does return both the path and URL, as long as you are passing a valid intermediate size name (e.g. 'medium') as the second parameter and not an array of height/width values.

Note: See TracTickets for help on using tickets.