#18691 closed enhancement (fixed)
Check for specific post formats with `current_theme_supports()`
Reported by: | ericmann | Owned by: | duck_ |
---|---|---|---|
Milestone: | 3.3 | Priority: | normal |
Severity: | normal | Version: | 3.2.1 |
Component: | Posts, Post Types | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
A question in IRC reminded me that there's no efficient way to check if a specific post format exists. At the moment, current_theme_supports()
is an all-or-nothing Boolean value ... either the theme supports post formats or it doesn't. There's no way to check for specific support for a particular format, say, "aside."
This could be added to current_theme_supports()
pretty easily and is done so in the attached patch.
current_theme_supports( 'post-formats' )
will returntrue
if any post format is supportedcurrent_theme_supports( 'post-formats', 'aside' )
will returntrue
if the "aside" post format is supported
Attachments (3)
Change History (10)
#2
follow-ups:
↓ 3
↓ 4
@
13 years ago
I think this patch can be simplified further. The logic is the same as that for post thumbnails, so it can use the same case statement.
case 'post-thumbnails': case 'post-formats': // bla
Haven't tested it though.
#3
in reply to:
↑ 2
@
13 years ago
- Milestone changed from Awaiting Review to 3.3
Replying to johnbillion:
I think this patch can be simplified further. The logic is the same as that for post thumbnails, so it can use the same case statement.
It's not entirely the same though due to:
if ( true === $_wp_theme_features[$feature] ) // Registered for all types return true;
for post-thumbnails.
#4
in reply to:
↑ 2
@
13 years ago
Replying to johnbillion:
I think this patch can be simplified further. The logic is the same as that for post thumbnails, so it can use the same case statement.
I'm tempted to agree, but I'm concerned that a fall-through case statement might not be very clear for others looking at the code later. Considering this coding standard:
In general, readability is more important than cleverness or brevity.
Fall-though case statements usually aren't very self-explanatory ... particularly if we ever add new cases to the statement. I'd rather leave in the full code now than need to re-add it if/when we add new cases down the road.
Allow selection of specific post type in
current_theme_supports()