Opened 9 years ago
Last modified 4 months ago
#33959 new enhancement
Improve wp_get_attachment_thumb_file
Reported by: | Rahe | Owned by: | |
---|---|---|---|
Milestone: | 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)
Change History (8)
#1
@
9 years ago
- Component changed from Post Thumbnails to Media
- Keywords has-patch needs-refresh needs-unit-tests added
#2
@
9 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:
↓ 5
↓ 6
@
9 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.
9 years ago
#5
in reply to:
↑ 3
@
9 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
@
9 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.
I'd rather introduce a new
wp_get_attachment_file( $post, $size )
function.wp_get_attachment_thumb_file()
could then simply be a wrapper forwp_get_attachment_file( $post = null, $size = 'thumb' )