get_post_class() does not always apply filter to output
|Reported by:||F J Kaiser||Owned by:||SergeyBiryukov|
|Component:||Posts, Post Types||Keywords:||has-patch|
Currently the post class function/template tag simply returns an empty array for 404 requests. The reason is simple: The output gets generated based on the return values of get_post().
This avoids using it to style parts of the 404 template using the post_class filter.
Use case: In one theme I'm currently developing, I use the post_class filter to override the parent themes classes with some grid classes from a CSS framework. This avoids duplicating the templates and handle the positions, etc. of the template parts with a simple callback for the post_class filter. The attached patch makes sure that classes get added, instead of just returning an empty array if no $post->ID is present. It doesn't harm any other callback (or interfere with it).
The attached patch is tested in current 3.4.2 and 3.5 Beta. It is built against the v3.5 nightly build - revision 606806.
Sidenote: The somehow wired phpDocBlock comment was also "fixed".
Change History (43)
@F J Kaiser
3 years ago
- Summary changed from Allow post class for 404 requests to get_post_class() does not always apply filter to output
- Type changed from enhancement to defect (bug)
3 years ago
- Cc mike@… added
- Keywords close added; dev-feedback removed