WordPress.org

Make WordPress Core

Changeset 26350


Ignore:
Timestamp:
11/24/2013 01:44:42 PM (6 years ago)
Author:
duck_
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post-formats.php

    r24817 r26350  
    3333
    3434/**
    35  * Check if a post has a particular format
     35 * Check if a post has any of the given formats, or any format.
    3636 *
    3737 * @since 3.1.0
     
    3939 * @uses has_term()
    4040 *
    41  * @param string|array $format The format or formats to check.
    42  * @param object|int   $post   The post to check. If not supplied, defaults to the current post if used in the loop.
    43  * @return bool True if the post has the format, false otherwise.
    44  */
    45 function has_post_format( $format, $post = null ) {
    46     if ( ! is_array( $format ) )
    47         $format = array( $format );
    48 
     41 * @param string|array $format Optional. The format or formats to check.
     42 * @param object|int $post Optional. The post to check. If not supplied, defaults to the current post if used in the loop.
     43 * @return bool True if the post has any of the given formats (or any format, if no format specified), false otherwise.
     44 */
     45function has_post_format( $format = array(), $post = null ) {
    4946    $prefixed = array();
    50     foreach( $format as $single ) {
    51         $prefixed[] = 'post-format-' . sanitize_key( $single );
     47
     48    if ( $format ) {
     49        foreach ( (array) $format as $single ) {
     50            $prefixed[] = 'post-format-' . sanitize_key( $single );
     51        }
    5252    }
    5353
Note: See TracChangeset for help on using the changeset viewer.