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
This commit is contained in:
Scott Taylor 2013-09-06 17:27:08 +00:00
parent 3a28152826
commit bfdc55b24d

View File

@ -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;