WordPress.org

Make WordPress Core

Opened 9 months ago

Closed 5 months ago

#24906 closed defect (bug) (fixed)

Post Formats: Allow to check for any post format

Reported by: obenland Owned by: duck_
Milestone: 3.8 Priority: normal
Severity: normal Version: 3.8
Component: Post Formats Keywords: has-patch commit
Focuses: Cc:

Description

It would be great if themes could check if any post format has been assigned to a post. This would make it especially easy to check if no post format has been assigned, something that is hard to do in has_post_format's current setup.

With the change in r24934 it is only a matter of making the passed format argument optional and checking for it.

Attachments (3)

24906.diff (1.2 KB) - added by obenland 9 months ago.
24906.2.diff (1.4 KB) - added by DrewAPicture 9 months ago.
24906.3.diff (1.4 KB) - added by nacin 8 months ago.

Download all attachments as: .zip

Change History (7)

obenland9 months ago

comment:1 DrewAPicture9 months ago

+1 for this. @obenland: Looks like you missed marking $format (optional) in the docblock.

We need to update the short description anyway following [24934] since it can (currently) be one or many.

DrewAPicture9 months ago

nacin8 months ago

comment:2 nacin8 months ago

The use of ! empty( $single ) felt like a code smell — under what circumstances would an item in this array be empty? It seems like that could occur if someone passed false, null, etc., as $format, which would then get converted to array( 0 => false ).

24906.3.diff tries a different branching of the logic.

comment:3 nacin7 months ago

  • Keywords commit added
  • Milestone changed from 3.7 to 3.8

comment:4 duck_5 months ago

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

In 26350:

Allow has_post_format() to be used to check for any format.

Calling has_post_format() with an empty list of $format will check if the
provided post has any associated format at all.

Props obenland, DrewAPicture, nacin. Fixes #24906.

Note: See TracTickets for help on using tickets.