Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#18691 closed enhancement (fixed)

Check for specific post formats with `current_theme_supports()`

Reported by: ericmann's profile ericmann Owned by: duck_'s profile 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 return true if any post format is supported
  • current_theme_supports( 'post-formats', 'aside' ) will return true if the "aside" post format is supported

Attachments (3)

current_theme_supports.diff (551 bytes) - added by ericmann 12 years ago.
Allow selection of specific post type in current_theme_supports()
current_theme_supports-2.diff (799 bytes) - added by ericmann 12 years ago.
Change variable name to match what we're doing. Use a cleaner return.
making-use-of-18691.diff (1.9 KB) - added by duck_ 12 years ago.

Download all attachments as: .zip

Change History (10)

@ericmann
12 years ago

Allow selection of specific post type in current_theme_supports()

#1 @larsemil
12 years ago

This is exactly what i was looking for. Will test and get back.

@ericmann
12 years ago

Change variable name to match what we're doing. Use a cleaner return.

#2 follow-ups: @johnbillion
12 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 @duck_
12 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 @ericmann
12 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.

Version 0, edited 12 years ago by ericmann (next)

#5 @duck_
12 years ago

  • Owner set to duck_
  • Resolution set to fixed
  • Status changed from new to closed

In [18720]:

Allow current_theme_supports() to be used to check for specific post formats. Props ericmann. Fixes #18691.

#6 @duck_
12 years ago

In [18721]:

Make use of specific post format support in current_theme_supports(). See #18691.

#7 @duck_
12 years ago

Related: #11611

Note: See TracTickets for help on using tickets.