Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#18691 closed enhancement (fixed)

Check for specific post formats with `current_theme_supports()`

Reported by: ericmann Owned by: duck_
Priority: normal Milestone: 3.3
Component: Posts, Post Types Version: 3.2.1
Severity: normal Keywords: has-patch needs-testing
Cc: Focuses:

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 15 years ago.
Allow selection of specific post type in current_theme_supports()
current_theme_supports-2.diff​ (799 bytes ) - added by ericmann 15 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_ 15 years ago.

Download all attachments as: .zip

Change History (10)

@ericmann
15 years ago

Allow selection of specific post type in current_theme_supports()

#1 @larsemil
15 years ago

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

@ericmann
15 years ago

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

#2 follow-ups: @johnbillion
15 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_
15 years ago

  • Milestone Awaiting Review → 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
15 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.

Last edited 15 years ago by ericmann (previous) (diff)

#5 @duck_
15 years ago

  • Owner set to duck_
  • Resolution → fixed
  • Status new → closed

In [18720]:

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

#6 @duck_
15 years ago

In [18721]:

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

#7 @duck_
15 years ago

Related: #11611

Note: See TracTickets for help on using tickets.