wp/wp-includes/category-template.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    88 
    88 
    89 	/**
    89 	/**
    90 	 * Filters the array of categories to return for a post.
    90 	 * Filters the array of categories to return for a post.
    91 	 *
    91 	 *
    92 	 * @since 3.1.0
    92 	 * @since 3.1.0
    93 	 * @since 4.4.0 Added `$post_id` parameter.
    93 	 * @since 4.4.0 Added the `$post_id` parameter.
    94 	 *
    94 	 *
    95 	 * @param WP_Term[] $categories An array of categories to return for the post.
    95 	 * @param WP_Term[] $categories An array of categories to return for the post.
    96 	 * @param int|false $post_id    ID of the post.
    96 	 * @param int|false $post_id    The post ID.
    97 	 */
    97 	 */
    98 	return apply_filters( 'get_the_categories', $categories, $post_id );
    98 	return apply_filters( 'get_the_categories', $categories, $post_id );
    99 }
    99 }
   100 
   100 
   101 /**
   101 /**
   131  *
   131  *
   132  * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
   132  * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
   133  *
   133  *
   134  * @param string $separator Optional. Separator between the categories. By default, the links are placed
   134  * @param string $separator Optional. Separator between the categories. By default, the links are placed
   135  *                          in an unordered list. An empty string will result in the default behavior.
   135  *                          in an unordered list. An empty string will result in the default behavior.
   136  * @param string $parents   Optional. How to display the parents.
   136  * @param string $parents   Optional. How to display the parents. Accepts 'multiple', 'single', or empty.
   137  * @param int    $post_id   Optional. Post ID to retrieve categories.
   137  *                          Default empty string.
       
   138  * @param int    $post_id   Optional. ID of the post to retrieve categories for. Defaults to the current post.
   138  * @return string Category list for a post.
   139  * @return string Category list for a post.
   139  */
   140  */
   140 function get_the_category_list( $separator = '', $parents = '', $post_id = false ) {
   141 function get_the_category_list( $separator = '', $parents = '', $post_id = false ) {
   141 	global $wp_rewrite;
   142 	global $wp_rewrite;
   142 
   143 
   149 	 * Filters the categories before building the category list.
   150 	 * Filters the categories before building the category list.
   150 	 *
   151 	 *
   151 	 * @since 4.4.0
   152 	 * @since 4.4.0
   152 	 *
   153 	 *
   153 	 * @param WP_Term[] $categories An array of the post's categories.
   154 	 * @param WP_Term[] $categories An array of the post's categories.
   154 	 * @param int|bool  $post_id    ID of the post we're retrieving categories for.
   155 	 * @param int|false $post_id    ID of the post to retrieve categories for.
   155 	 *                              When `false`, we assume the current post in the loop.
   156 	 *                              When `false`, defaults to the current post in the loop.
   156 	 */
   157 	 */
   157 	$categories = apply_filters( 'the_category_list', get_the_category( $post_id ), $post_id );
   158 	$categories = apply_filters( 'the_category_list', get_the_category( $post_id ), $post_id );
   158 
   159 
   159 	if ( empty( $categories ) ) {
   160 	if ( empty( $categories ) ) {
   160 		/** This filter is documented in wp-includes/category-template.php */
   161 		/** This filter is documented in wp-includes/category-template.php */
   248  * @since 1.2.0
   249  * @since 1.2.0
   249  * @since 2.7.0 The `$post` parameter was added.
   250  * @since 2.7.0 The `$post` parameter was added.
   250  *
   251  *
   251  * @param int|string|int[]|string[] $category Category ID, name, slug, or array of such
   252  * @param int|string|int[]|string[] $category Category ID, name, slug, or array of such
   252  *                                            to check against.
   253  *                                            to check against.
   253  * @param int|object                $post     Optional. Post to check instead of the current post.
   254  * @param int|WP_Post               $post     Optional. Post to check. Defaults to the current post.
   254  * @return bool True if the current post is in any of the given categories.
   255  * @return bool True if the current post is in any of the given categories.
   255  */
   256  */
   256 function in_category( $category, $post = null ) {
   257 function in_category( $category, $post = null ) {
   257 	if ( empty( $category ) ) {
   258 	if ( empty( $category ) ) {
   258 		return false;
   259 		return false;
   266  *
   267  *
   267  * @since 0.71
   268  * @since 0.71
   268  *
   269  *
   269  * @param string $separator Optional. Separator between the categories. By default, the links are placed
   270  * @param string $separator Optional. Separator between the categories. By default, the links are placed
   270  *                          in an unordered list. An empty string will result in the default behavior.
   271  *                          in an unordered list. An empty string will result in the default behavior.
   271  * @param string $parents   Optional. How to display the parents.
   272  * @param string $parents   Optional. How to display the parents. Accepts 'multiple', 'single', or empty.
   272  * @param int    $post_id   Optional. Post ID to retrieve categories.
   273  *                          Default empty string.
       
   274  * @param int    $post_id   Optional. ID of the post to retrieve categories for. Defaults to the current post.
   273  */
   275  */
   274 function the_category( $separator = '', $parents = '', $post_id = false ) {
   276 function the_category( $separator = '', $parents = '', $post_id = false ) {
   275 	echo get_the_category_list( $separator, $parents, $post_id );
   277 	echo get_the_category_list( $separator, $parents, $post_id );
   276 }
   278 }
   277 
   279 
   296  * the 'depth' argument.
   298  * the 'depth' argument.
   297  *
   299  *
   298  * @since 2.1.0
   300  * @since 2.1.0
   299  * @since 4.2.0 Introduced the `value_field` argument.
   301  * @since 4.2.0 Introduced the `value_field` argument.
   300  * @since 4.6.0 Introduced the `required` argument.
   302  * @since 4.6.0 Introduced the `required` argument.
       
   303  * @since 6.1.0 Introduced the `aria_describedby` argument.
   301  *
   304  *
   302  * @param array|string $args {
   305  * @param array|string $args {
   303  *     Optional. Array or string of arguments to generate a categories drop-down element. See WP_Term_Query::__construct()
   306  *     Optional. Array or string of arguments to generate a categories drop-down element. See WP_Term_Query::__construct()
   304  *     for information on additional accepted arguments.
   307  *     for information on additional accepted arguments.
   305  *
   308  *
   331  *                                           Default false (create select element even if no categories are found).
   334  *                                           Default false (create select element even if no categories are found).
   332  *     @type bool         $required          Whether the `<select>` element should have the HTML5 'required' attribute.
   335  *     @type bool         $required          Whether the `<select>` element should have the HTML5 'required' attribute.
   333  *                                           Default false.
   336  *                                           Default false.
   334  *     @type Walker       $walker            Walker object to use to build the output. Default empty which results in a
   337  *     @type Walker       $walker            Walker object to use to build the output. Default empty which results in a
   335  *                                           Walker_CategoryDropdown instance being used.
   338  *                                           Walker_CategoryDropdown instance being used.
       
   339  *     @type string       $aria_describedby  The 'id' of an element that contains descriptive text for the select.
       
   340  *                                           Default empty string.
   336  * }
   341  * }
   337  * @return string HTML dropdown list of categories.
   342  * @return string HTML dropdown list of categories.
   338  */
   343  */
   339 function wp_dropdown_categories( $args = '' ) {
   344 function wp_dropdown_categories( $args = '' ) {
   340 	$defaults = array(
   345 	$defaults = array(
   357 		'taxonomy'          => 'category',
   362 		'taxonomy'          => 'category',
   358 		'hide_if_empty'     => false,
   363 		'hide_if_empty'     => false,
   359 		'option_none_value' => -1,
   364 		'option_none_value' => -1,
   360 		'value_field'       => 'term_id',
   365 		'value_field'       => 'term_id',
   361 		'required'          => false,
   366 		'required'          => false,
       
   367 		'aria_describedby'  => '',
   362 	);
   368 	);
   363 
   369 
   364 	$defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
   370 	$defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
   365 
   371 
   366 	// Back compat.
   372 	// Back compat.
   402 	$name     = esc_attr( $parsed_args['name'] );
   408 	$name     = esc_attr( $parsed_args['name'] );
   403 	$class    = esc_attr( $parsed_args['class'] );
   409 	$class    = esc_attr( $parsed_args['class'] );
   404 	$id       = $parsed_args['id'] ? esc_attr( $parsed_args['id'] ) : $name;
   410 	$id       = $parsed_args['id'] ? esc_attr( $parsed_args['id'] ) : $name;
   405 	$required = $parsed_args['required'] ? 'required' : '';
   411 	$required = $parsed_args['required'] ? 'required' : '';
   406 
   412 
       
   413 	$aria_describedby_attribute = $parsed_args['aria_describedby'] ? ' aria-describedby="' . esc_attr( $parsed_args['aria_describedby'] ) . '"' : '';
       
   414 
   407 	if ( ! $parsed_args['hide_if_empty'] || ! empty( $categories ) ) {
   415 	if ( ! $parsed_args['hide_if_empty'] || ! empty( $categories ) ) {
   408 		$output = "<select $required name='$name' id='$id' class='$class' $tab_index_attribute>\n";
   416 		$output = "<select $required name='$name' id='$id' class='$class'$tab_index_attribute$aria_describedby_attribute>\n";
   409 	} else {
   417 	} else {
   410 		$output = '';
   418 		$output = '';
   411 	}
   419 	}
   412 	if ( empty( $categories ) && ! $parsed_args['hide_if_empty'] && ! empty( $parsed_args['show_option_none'] ) ) {
   420 	if ( empty( $categories ) && ! $parsed_args['hide_if_empty'] && ! empty( $parsed_args['show_option_none'] ) ) {
   413 
   421 
   481  * Displays or retrieves the HTML list of categories.
   489  * Displays or retrieves the HTML list of categories.
   482  *
   490  *
   483  * @since 2.1.0
   491  * @since 2.1.0
   484  * @since 4.4.0 Introduced the `hide_title_if_empty` and `separator` arguments.
   492  * @since 4.4.0 Introduced the `hide_title_if_empty` and `separator` arguments.
   485  * @since 4.4.0 The `current_category` argument was modified to optionally accept an array of values.
   493  * @since 4.4.0 The `current_category` argument was modified to optionally accept an array of values.
       
   494  * @since 6.1.0 Default value of the 'use_desc_for_title' argument was changed from 1 to 0.
   486  *
   495  *
   487  * @param array|string $args {
   496  * @param array|string $args {
   488  *     Array of optional arguments. See get_categories(), get_terms(), and WP_Term_Query::__construct()
   497  *     Array of optional arguments. See get_categories(), get_terms(), and WP_Term_Query::__construct()
   489  *     for information on additional accepted arguments.
   498  *     for information on additional accepted arguments.
   490  *
   499  *
   517  *                                               categories will be output separated by `<br>` tags. Default 'list'.
   526  *                                               categories will be output separated by `<br>` tags. Default 'list'.
   518  *     @type string       $taxonomy              Name of the taxonomy to retrieve. Default 'category'.
   527  *     @type string       $taxonomy              Name of the taxonomy to retrieve. Default 'category'.
   519  *     @type string       $title_li              Text to use for the list title `<li>` element. Pass an empty string
   528  *     @type string       $title_li              Text to use for the list title `<li>` element. Pass an empty string
   520  *                                               to disable. Default 'Categories'.
   529  *                                               to disable. Default 'Categories'.
   521  *     @type bool|int     $use_desc_for_title    Whether to use the category description as the title attribute.
   530  *     @type bool|int     $use_desc_for_title    Whether to use the category description as the title attribute.
   522  *                                               Accepts 0, 1, or their bool equivalents. Default 1.
   531  *                                               Accepts 0, 1, or their bool equivalents. Default 0.
   523  *     @type Walker       $walker                Walker object to use to build the output. Default empty which results
   532  *     @type Walker       $walker                Walker object to use to build the output. Default empty which results
   524  *                                               in a Walker_Category instance being used.
   533  *                                               in a Walker_Category instance being used.
   525  * }
   534  * }
   526  * @return void|string|false Void if 'echo' argument is true, HTML list of categories if 'echo' is false.
   535  * @return void|string|false Void if 'echo' argument is true, HTML list of categories if 'echo' is false.
   527  *                           False if the taxonomy does not exist.
   536  *                           False if the taxonomy does not exist.
   547 		'show_option_all'     => '',
   556 		'show_option_all'     => '',
   548 		'show_option_none'    => __( 'No categories' ),
   557 		'show_option_none'    => __( 'No categories' ),
   549 		'style'               => 'list',
   558 		'style'               => 'list',
   550 		'taxonomy'            => 'category',
   559 		'taxonomy'            => 'category',
   551 		'title_li'            => __( 'Categories' ),
   560 		'title_li'            => __( 'Categories' ),
   552 		'use_desc_for_title'  => 1,
   561 		'use_desc_for_title'  => 0,
   553 	);
   562 	);
   554 
   563 
   555 	$parsed_args = wp_parse_args( $args, $defaults );
   564 	$parsed_args = wp_parse_args( $args, $defaults );
   556 
   565 
   557 	if ( ! isset( $parsed_args['pad_counts'] ) && $parsed_args['show_count'] && $parsed_args['hierarchical'] ) {
   566 	if ( ! isset( $parsed_args['pad_counts'] ) && $parsed_args['show_count'] && $parsed_args['hierarchical'] ) {
   558 		$parsed_args['pad_counts'] = true;
   567 		$parsed_args['pad_counts'] = true;
   559 	}
   568 	}
   560 
   569 
   561 	// Descendants of exclusions should be excluded too.
   570 	// Descendants of exclusions should be excluded too.
   562 	if ( true == $parsed_args['hierarchical'] ) {
   571 	if ( $parsed_args['hierarchical'] ) {
   563 		$exclude_tree = array();
   572 		$exclude_tree = array();
   564 
   573 
   565 		if ( $parsed_args['exclude_tree'] ) {
   574 		if ( $parsed_args['exclude_tree'] ) {
   566 			$exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $parsed_args['exclude_tree'] ) );
   575 			$exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $parsed_args['exclude_tree'] ) );
   567 		}
   576 		}
   820  *                                                can also affect how tags are sorted.
   829  *                                                can also affect how tags are sorted.
   821  *     @type string   $order                      How to order the tags. Accepts 'ASC' (ascending),
   830  *     @type string   $order                      How to order the tags. Accepts 'ASC' (ascending),
   822  *                                                'DESC' (descending), or 'RAND' (random). Default 'ASC'.
   831  *                                                'DESC' (descending), or 'RAND' (random). Default 'ASC'.
   823  *     @type int|bool $filter                     Whether to enable filtering of the final output
   832  *     @type int|bool $filter                     Whether to enable filtering of the final output
   824  *                                                via {@see 'wp_generate_tag_cloud'}. Default 1.
   833  *                                                via {@see 'wp_generate_tag_cloud'}. Default 1.
   825  *     @type string   $topic_count_text           Nooped plural text from _n_noop() to supply to
   834  *     @type array    $topic_count_text           Nooped plural text from _n_noop() to supply to
   826  *                                                tag counts. Default null.
   835  *                                                tag counts. Default null.
   827  *     @type callable $topic_count_text_callback  Callback used to generate nooped plural text for
   836  *     @type callable $topic_count_text_callback  Callback used to generate nooped plural text for
   828  *                                                tag counts based on the count. Default null.
   837  *                                                tag counts based on the count. Default null.
   829  *     @type callable $topic_count_scale_callback Callback used to determine the tag count scaling
   838  *     @type callable $topic_count_scale_callback Callback used to determine the tag count scaling
   830  *                                                value. Default default_topic_count_scale().
   839  *                                                value. Default default_topic_count_scale().
   870 		} else {
   879 		} else {
   871 			$translate_nooped_plural = false;
   880 			$translate_nooped_plural = false;
   872 		}
   881 		}
   873 	} elseif ( isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
   882 	} elseif ( isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
   874 		// If no callback exists, look for the old-style single_text and multiple_text arguments.
   883 		// If no callback exists, look for the old-style single_text and multiple_text arguments.
   875 		// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralSingle,WordPress.WP.I18n.NonSingularStringLiteralPlural
   884 		// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralSingular,WordPress.WP.I18n.NonSingularStringLiteralPlural
   876 		$translate_nooped_plural = _n_noop( $args['single_text'], $args['multiple_text'] );
   885 		$translate_nooped_plural = _n_noop( $args['single_text'], $args['multiple_text'] );
   877 	} else {
   886 	} else {
   878 		// This is the default for when no callback, plural, or argument is passed in.
   887 		// This is the default for when no callback, plural, or argument is passed in.
   879 		/* translators: %s: Number of items (tags). */
   888 		/* translators: %s: Number of items (tags). */
   880 		$translate_nooped_plural = _n_noop( '%s item', '%s items' );
   889 		$translate_nooped_plural = _n_noop( '%s item', '%s items' );
  1073  * @since 3.1.0
  1082  * @since 3.1.0
  1074  * @access private
  1083  * @access private
  1075  *
  1084  *
  1076  * @param object $a The first object to compare.
  1085  * @param object $a The first object to compare.
  1077  * @param object $b The second object to compare.
  1086  * @param object $b The second object to compare.
  1078  * @return bool Whether the count value for `$a` is greater than the count value for `$b`.
  1087  * @return int Negative number if `$a->count` is less than `$b->count`, zero if they are equal,
       
  1088  *             or greater than zero if `$a->count` is greater than `$b->count`.
  1079  */
  1089  */
  1080 function _wp_object_count_sort_cb( $a, $b ) {
  1090 function _wp_object_count_sort_cb( $a, $b ) {
  1081 	return ( $a->count > $b->count );
  1091 	return ( $a->count - $b->count );
  1082 }
  1092 }
  1083 
  1093 
  1084 //
  1094 //
  1085 // Helper functions.
  1095 // Helper functions.
  1086 //
  1096 //
  1099  * @return string
  1109  * @return string
  1100  */
  1110  */
  1101 function walk_category_tree( ...$args ) {
  1111 function walk_category_tree( ...$args ) {
  1102 	// The user's options are the third parameter.
  1112 	// The user's options are the third parameter.
  1103 	if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) {
  1113 	if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) {
  1104 		$walker = new Walker_Category;
  1114 		$walker = new Walker_Category();
  1105 	} else {
  1115 	} else {
  1106 		/**
  1116 		/**
  1107 		 * @var Walker $walker
  1117 		 * @var Walker $walker
  1108 		 */
  1118 		 */
  1109 		$walker = $args[2]['walker'];
  1119 		$walker = $args[2]['walker'];
  1125  * @return string
  1135  * @return string
  1126  */
  1136  */
  1127 function walk_category_dropdown_tree( ...$args ) {
  1137 function walk_category_dropdown_tree( ...$args ) {
  1128 	// The user's options are the third parameter.
  1138 	// The user's options are the third parameter.
  1129 	if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) {
  1139 	if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) {
  1130 		$walker = new Walker_CategoryDropdown;
  1140 		$walker = new Walker_CategoryDropdown();
  1131 	} else {
  1141 	} else {
  1132 		/**
  1142 		/**
  1133 		 * @var Walker $walker
  1143 		 * @var Walker $walker
  1134 		 */
  1144 		 */
  1135 		$walker = $args[2]['walker'];
  1145 		$walker = $args[2]['walker'];
  1158 /**
  1168 /**
  1159  * Retrieves the tags for a post.
  1169  * Retrieves the tags for a post.
  1160  *
  1170  *
  1161  * @since 2.3.0
  1171  * @since 2.3.0
  1162  *
  1172  *
  1163  * @param int|WP_Post $post_id Post ID or object.
  1173  * @param int|WP_Post $post Post ID or object.
  1164  * @return WP_Term[]|false|WP_Error Array of WP_Term objects on success, false if there are no terms
  1174  * @return WP_Term[]|false|WP_Error Array of WP_Term objects on success, false if there are no terms
  1165  *                                  or the post does not exist, WP_Error on failure.
  1175  *                                  or the post does not exist, WP_Error on failure.
  1166  */
  1176  */
  1167 function get_the_tags( $post_id = 0 ) {
  1177 function get_the_tags( $post = 0 ) {
  1168 	$terms = get_the_terms( $post_id, 'post_tag' );
  1178 	$terms = get_the_terms( $post, 'post_tag' );
  1169 
  1179 
  1170 	/**
  1180 	/**
  1171 	 * Filters the array of tags for the given post.
  1181 	 * Filters the array of tags for the given post.
  1172 	 *
  1182 	 *
  1173 	 * @since 2.3.0
  1183 	 * @since 2.3.0
  1275  * @return WP_Term[]|false|WP_Error Array of WP_Term objects on success, false if there are no terms
  1285  * @return WP_Term[]|false|WP_Error Array of WP_Term objects on success, false if there are no terms
  1276  *                                  or the post does not exist, WP_Error on failure.
  1286  *                                  or the post does not exist, WP_Error on failure.
  1277  */
  1287  */
  1278 function get_the_terms( $post, $taxonomy ) {
  1288 function get_the_terms( $post, $taxonomy ) {
  1279 	$post = get_post( $post );
  1289 	$post = get_post( $post );
       
  1290 
  1280 	if ( ! $post ) {
  1291 	if ( ! $post ) {
  1281 		return false;
  1292 		return false;
  1282 	}
  1293 	}
  1283 
  1294 
  1284 	$terms = get_object_term_cache( $post->ID, $taxonomy );
  1295 	$terms = get_object_term_cache( $post->ID, $taxonomy );
       
  1296 
  1285 	if ( false === $terms ) {
  1297 	if ( false === $terms ) {
  1286 		$terms = wp_get_object_terms( $post->ID, $taxonomy );
  1298 		$terms = wp_get_object_terms( $post->ID, $taxonomy );
  1287 		if ( ! is_wp_error( $terms ) ) {
  1299 		if ( ! is_wp_error( $terms ) ) {
  1288 			$term_ids = wp_list_pluck( $terms, 'term_id' );
  1300 			$term_ids = wp_list_pluck( $terms, 'term_id' );
  1289 			wp_cache_add( $post->ID, $term_ids, $taxonomy . '_relationships' );
  1301 			wp_cache_add( $post->ID, $term_ids, $taxonomy . '_relationships' );
  1473  *
  1485  *
  1474  * @since 3.1.0
  1486  * @since 3.1.0
  1475  *
  1487  *
  1476  * @param string|int|array $category Optional. The category name/term_id/slug,
  1488  * @param string|int|array $category Optional. The category name/term_id/slug,
  1477  *                                   or an array of them to check for. Default empty.
  1489  *                                   or an array of them to check for. Default empty.
  1478  * @param int|object       $post     Optional. Post to check instead of the current post.
  1490  * @param int|WP_Post      $post     Optional. Post to check. Defaults to the current post.
  1479  * @return bool True if the current post has any of the given categories
  1491  * @return bool True if the current post has any of the given categories
  1480  *              (or any category, if no category specified). False otherwise.
  1492  *              (or any category, if no category specified). False otherwise.
  1481  */
  1493  */
  1482 function has_category( $category = '', $post = null ) {
  1494 function has_category( $category = '', $post = null ) {
  1483 	return has_term( $category, 'category', $post );
  1495 	return has_term( $category, 'category', $post );
  1500  *              the post's tags' term_ids, not names or slugs.
  1512  *              the post's tags' term_ids, not names or slugs.
  1501  * @since 2.7.0 Can be used outside of the WordPress Loop if `$post` is provided.
  1513  * @since 2.7.0 Can be used outside of the WordPress Loop if `$post` is provided.
  1502  *
  1514  *
  1503  * @param string|int|array $tag  Optional. The tag name/term_id/slug,
  1515  * @param string|int|array $tag  Optional. The tag name/term_id/slug,
  1504  *                               or an array of them to check for. Default empty.
  1516  *                               or an array of them to check for. Default empty.
  1505  * @param int|object       $post Optional. Post to check instead of the current post.
  1517  * @param int|WP_Post      $post Optional. Post to check. Defaults to the current post.
  1506  * @return bool True if the current post has any of the given tags
  1518  * @return bool True if the current post has any of the given tags
  1507  *              (or any tag, if no tag specified). False otherwise.
  1519  *              (or any tag, if no tag specified). False otherwise.
  1508  */
  1520  */
  1509 function has_tag( $tag = '', $post = null ) {
  1521 function has_tag( $tag = '', $post = null ) {
  1510 	return has_term( $tag, 'post_tag', $post );
  1522 	return has_term( $tag, 'post_tag', $post );
  1521  * @since 3.1.0
  1533  * @since 3.1.0
  1522  *
  1534  *
  1523  * @param string|int|array $term     Optional. The term name/term_id/slug,
  1535  * @param string|int|array $term     Optional. The term name/term_id/slug,
  1524  *                                   or an array of them to check for. Default empty.
  1536  *                                   or an array of them to check for. Default empty.
  1525  * @param string           $taxonomy Optional. Taxonomy name. Default empty.
  1537  * @param string           $taxonomy Optional. Taxonomy name. Default empty.
  1526  * @param int|WP_Post      $post     Optional. Post to check instead of the current post.
  1538  * @param int|WP_Post      $post     Optional. Post to check. Defaults to the current post.
  1527  * @return bool True if the current post has any of the given terms
  1539  * @return bool True if the current post has any of the given terms
  1528  *              (or any term, if no term specified). False otherwise.
  1540  *              (or any term, if no term specified). False otherwise.
  1529  */
  1541  */
  1530 function has_term( $term = '', $taxonomy = '', $post = null ) {
  1542 function has_term( $term = '', $taxonomy = '', $post = null ) {
  1531 	$post = get_post( $post );
  1543 	$post = get_post( $post );