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)
comment:2 @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)
comment:8 @MikeSchinkel — 3 years ago
- Cc mike@… added
comment:15 follow-ups: ↓ 17 ↓ 18 @scribu — 3 years ago
comment:16 @scribu — 3 years ago
- Keywords close added; dev-feedback removed
comment:17 in reply to: ↑ 15 @MikeSchinkel — 3 years ago
comment:22 @nacin — 3 years ago
- Keywords close removed
- Type changed from defect (bug) to enhancement
comment:24 in reply to: ↑ 23 @nacin — 3 years ago
- Keywords needs-patch added; has-patch dev-feedback removed
comment:32 @nacin — 18 months ago
- Component changed from Template to Posts, Post Types
- Focuses template added