WordPress.org

Make WordPress Core

Ticket #17320: 17320.diff

File 17320.diff, 1.1 KB (added by elky, 7 years ago)

Catch arrays, check for non-string values, add prefix & send to has_term()

  • wp-includes/post.php

     
    506506 * @since 3.1.0
    507507 * @uses has_term()
    508508 *
    509  * @param string $format The format to check for
     509 * @param string|array $format The format to check for
    510510 * @param object|id $post The post to check. If not supplied, defaults to the current post if used in the loop.
    511511 * @return bool True if the post has the format, false otherwise.
    512512 */
    513513function has_post_format( $format, $post = null ) {
    514         return has_term('post-format-' . sanitize_key($format), 'post_format', $post);
     514        if ( is_array( $format ) ) {
     515                $format_prefixed = array();
     516                foreach ( $format as $f ) {
     517                        if ( !is_string( $f ) ) {
     518                                unset( $format_prefixed );
     519                                unset( $f );
     520                                return false;
     521                        }
     522                        $format_prefixed[] = 'post-format-' . sanitize_key( $f );
     523                }
     524                unset( $format_prefixed );
     525                unset( $f );
     526                return has_term( $format_prefixed, 'post_format', $post );
     527        }
     528        return has_term( 'post-format-' . sanitize_key( $format ), 'post_format', $post );
    515529}
    516530
    517531/**