Opened 20 months ago

Closed 20 months ago

Last modified 20 months 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: Post Types Version: 3.2.1
Severity: normal Keywords: has-patch needs-testing
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 20 months ago.
Allow selection of specific post type in current_theme_supports()
current_theme_supports-2.diff (799 bytes) - added by ericmann 20 months 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_ 20 months ago.

Download all attachments as: .zip

Change History (10)

Allow selection of specific post type in current_theme_supports()

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

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

comment:2 follow-ups: ↓ 3 ↓ 4   johnbillion20 months 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.

comment:3 in reply to: ↑ 2   duck_20 months 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.

comment:4 in reply to: ↑ 2   ericmann20 months 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 20 months ago by ericmann (previous) (diff)

duck_20 months 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.

In [18721]:

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

Related: #11611

Note: See TracTickets for help on using tickets.