Opened 8 years ago
Closed 7 years ago
#39030 closed enhancement (fixed)
Pass post object or post ID to post_thumbnail_size filter
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Post Thumbnails | Keywords: | good-first-bug has-patch has-unit-tests |
Focuses: | template | Cc: |
Description
As per title, an edit to the filter post_thumbnail_size as follow:
/** * Filters the post thumbnail size. * * @since 2.9.0 * * @param string|array $size The post thumbnail size. Image size or array of width and height * values (in that order). Default 'post-thumbnail'. * @param WP_Post $post The post object */ $size = apply_filters( 'post_thumbnail_size', $size, $post );
In this way we can retrieve additional info by the post to filter the size of the post outside of a loop.
Yes, there is a filter named post_thumbnail_html but in that case the purpose of the filter is to filter the html string.
Attachments (2)
Change History (7)
#1
@
8 years ago
- Keywords needs-patch good-first-bug added
- Milestone changed from Awaiting Review to 4.9
#3
@
8 years ago
- Keywords needs-unit-tests added
- Owner set to NathanAtmoz
- Status changed from new to assigned
Thanks for the patch @NathanAtmoz, looks good!
Please note that the parameter description as well as the since
annotation in the doc block need to end with a dot. However, you don't necessarily need to update the patch, since this can be done pre-commit. Just something to be aware of. :)
#4
@
7 years ago
- Keywords has-unit-tests added; needs-unit-tests removed
- Version 4.7 deleted
39030.diff passes the post ID instead of post object, to have consistency with the other filters in the function, and also in order to prevent the filter from changing object properties on the original instance.
Tests for the filter usage including the new parameter have been added too.
first pass at a patch