From bfdc55b24d0a9690e37e0b863ad04925137712a9 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 6 Sep 2013 17:27:08 +0000 Subject: [PATCH] Allow `is_tag()` to accept `term_id`, `slug`, 'term_name` or array of any. Many other `is_*()` funcs already do this. Adds unit tests. Props ramiy. Fixes #18746. Built from https://develop.svn.wordpress.org/trunk@25287 git-svn-id: http://core.svn.wordpress.org/trunk@25251 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/query.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index 0286072738..07838ab8b6 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -246,10 +246,10 @@ function is_category( $category = '' ) { * @since 2.3.0 * @uses $wp_query * - * @param mixed $slug Optional. Tag slug or array of slugs. + * @param mixed $tag Optional. Tag ID, name, slug, or array of Tag IDs, names, and slugs. * @return bool */ -function is_tag( $slug = '' ) { +function is_tag( $tag = '' ) { global $wp_query; if ( ! isset( $wp_query ) ) { @@ -257,7 +257,7 @@ function is_tag( $slug = '' ) { return false; } - return $wp_query->is_tag( $slug ); + return $wp_query->is_tag( $tag ); } /** @@ -3238,21 +3238,25 @@ class WP_Query { * * @since 3.1.0 * - * @param mixed $slug Optional. Tag slug or array of slugs. + * @param mixed $tag Optional. Tag ID, name, slug, or array of Tag IDs, names, and slugs. * @return bool */ - function is_tag( $slug = '' ) { - if ( !$this->is_tag ) + function is_tag( $tag = '' ) { + if ( ! $this->is_tag ) return false; - if ( empty( $slug ) ) + if ( empty( $tag ) ) return true; $tag_obj = $this->get_queried_object(); - $slug = (array) $slug; + $tag = (array) $tag; - if ( in_array( $tag_obj->slug, $slug ) ) + if ( in_array( $tag_obj->term_id, $tag ) ) + return true; + elseif ( in_array( $tag_obj->name, $tag ) ) + return true; + elseif ( in_array( $tag_obj->slug, $tag ) ) return true; return false;