From 88cc05b8f85dcf6306fd25371c7b12e16764c0f0 Mon Sep 17 00:00:00 2001 From: Jon Cave Date: Sun, 24 Nov 2013 13:44:42 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@26350 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post-formats.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/wp-includes/post-formats.php b/src/wp-includes/post-formats.php index a13de3eaa6..cdb9da5d73 100644 --- a/src/wp-includes/post-formats.php +++ b/src/wp-includes/post-formats.php @@ -32,23 +32,23 @@ function get_post_format( $post = null ) { } /** - * Check if a post has a particular format + * Check if a post has any of the given formats, or any format. * * @since 3.1.0 * * @uses has_term() * - * @param string|array $format The format or formats to check. - * @param object|int $post The post to check. If not supplied, defaults to the current post if used in the loop. - * @return bool True if the post has the format, false otherwise. + * @param string|array $format Optional. The format or formats to check. + * @param object|int $post Optional. The post to check. If not supplied, defaults to the current post if used in the loop. + * @return bool True if the post has any of the given formats (or any format, if no format specified), false otherwise. */ -function has_post_format( $format, $post = null ) { - if ( ! is_array( $format ) ) - $format = array( $format ); - +function has_post_format( $format = array(), $post = null ) { $prefixed = array(); - foreach( $format as $single ) { - $prefixed[] = 'post-format-' . sanitize_key( $single ); + + if ( $format ) { + foreach ( (array) $format as $single ) { + $prefixed[] = 'post-format-' . sanitize_key( $single ); + } } return has_term( $prefixed, 'post_format', $post );