wp/wp-includes/category-template.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    54 		$visited[] = $parent->parent;
    54 		$visited[] = $parent->parent;
    55 		$chain .= get_category_parents( $parent->parent, $link, $separator, $nicename, $visited );
    55 		$chain .= get_category_parents( $parent->parent, $link, $separator, $nicename, $visited );
    56 	}
    56 	}
    57 
    57 
    58 	if ( $link )
    58 	if ( $link )
    59 		$chain .= '<a href="' . esc_url( get_category_link( $parent->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
    59 		$chain .= '<a href="' . esc_url( get_category_link( $parent->term_id ) ) . '">'.$name.'</a>' . $separator;
    60 	else
    60 	else
    61 		$chain .= $name.$separator;
    61 		$chain .= $name.$separator;
    62 	return $chain;
    62 	return $chain;
    63 }
    63 }
    64 
    64 
    65 /**
    65 /**
    66  * Retrieve post categories.
    66  * Retrieve post categories.
    67  *
    67  *
    68  * @since 0.71
    68  * @since 0.71
    69  * @uses $post
       
    70  *
    69  *
    71  * @param int $id Optional, default to current post ID. The post ID.
    70  * @param int $id Optional, default to current post ID. The post ID.
    72  * @return array
    71  * @return array
    73  */
    72  */
    74 function get_the_category( $id = false ) {
    73 function get_the_category( $id = false ) {
    80 
    79 
    81 	foreach ( array_keys( $categories ) as $key ) {
    80 	foreach ( array_keys( $categories ) as $key ) {
    82 		_make_cat_compat( $categories[$key] );
    81 		_make_cat_compat( $categories[$key] );
    83 	}
    82 	}
    84 
    83 
    85 	// Filter name is plural because we return alot of categories (possibly more than #13237) not just one
    84 	/**
       
    85 	 * Filter the array of categories to return for a post.
       
    86 	 *
       
    87 	 * @since 3.1.0
       
    88 	 *
       
    89 	 * @param array $categories An array of categories to return for the post.
       
    90 	 */
    86 	return apply_filters( 'get_the_categories', $categories );
    91 	return apply_filters( 'get_the_categories', $categories );
    87 }
    92 }
    88 
    93 
    89 /**
    94 /**
    90  * Sort categories by name.
    95  * Sort categories by name.
   134  * @return string|WP_Error Category name on success, WP_Error on failure.
   139  * @return string|WP_Error Category name on success, WP_Error on failure.
   135  */
   140  */
   136 function get_the_category_by_ID( $cat_ID ) {
   141 function get_the_category_by_ID( $cat_ID ) {
   137 	$cat_ID = (int) $cat_ID;
   142 	$cat_ID = (int) $cat_ID;
   138 	$category = get_term( $cat_ID, 'category' );
   143 	$category = get_term( $cat_ID, 'category' );
       
   144 
   139 	if ( is_wp_error( $category ) )
   145 	if ( is_wp_error( $category ) )
   140 		return $category;
   146 		return $category;
   141 	return $category->name;
   147 
       
   148 	return ( $category ) ? $category->name : '';
   142 }
   149 }
   143 
   150 
   144 /**
   151 /**
   145  * Retrieve category list in either HTML list or custom format.
   152  * Retrieve category list in either HTML list or custom format.
   146  *
   153  *
   151  * @param int $post_id Optional. Post ID to retrieve categories.
   158  * @param int $post_id Optional. Post ID to retrieve categories.
   152  * @return string
   159  * @return string
   153  */
   160  */
   154 function get_the_category_list( $separator = '', $parents='', $post_id = false ) {
   161 function get_the_category_list( $separator = '', $parents='', $post_id = false ) {
   155 	global $wp_rewrite;
   162 	global $wp_rewrite;
   156 	if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) )
   163 	if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) ) {
       
   164 		/** This filter is documented in wp-includes/category-template.php */
   157 		return apply_filters( 'the_category', '', $separator, $parents );
   165 		return apply_filters( 'the_category', '', $separator, $parents );
       
   166 	}
   158 
   167 
   159 	$categories = get_the_category( $post_id );
   168 	$categories = get_the_category( $post_id );
   160 	if ( empty( $categories ) )
   169 	if ( empty( $categories ) ) {
       
   170 		/** This filter is documented in wp-includes/category-template.php */
   161 		return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents );
   171 		return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents );
       
   172 	}
   162 
   173 
   163 	$rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';
   174 	$rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';
   164 
   175 
   165 	$thelist = '';
   176 	$thelist = '';
   166 	if ( '' == $separator ) {
   177 	if ( '' == $separator ) {
   169 			$thelist .= "\n\t<li>";
   180 			$thelist .= "\n\t<li>";
   170 			switch ( strtolower( $parents ) ) {
   181 			switch ( strtolower( $parents ) ) {
   171 				case 'multiple':
   182 				case 'multiple':
   172 					if ( $category->parent )
   183 					if ( $category->parent )
   173 						$thelist .= get_category_parents( $category->parent, true, $separator );
   184 						$thelist .= get_category_parents( $category->parent, true, $separator );
   174 					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';
   185 					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';
   175 					break;
   186 					break;
   176 				case 'single':
   187 				case 'single':
   177 					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>';
   188 					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '"  ' . $rel . '>';
   178 					if ( $category->parent )
   189 					if ( $category->parent )
   179 						$thelist .= get_category_parents( $category->parent, false, $separator );
   190 						$thelist .= get_category_parents( $category->parent, false, $separator );
   180 					$thelist .= $category->name.'</a></li>';
   191 					$thelist .= $category->name.'</a></li>';
   181 					break;
   192 					break;
   182 				case '':
   193 				case '':
   183 				default:
   194 				default:
   184 					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';
   195 					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';
   185 			}
   196 			}
   186 		}
   197 		}
   187 		$thelist .= '</ul>';
   198 		$thelist .= '</ul>';
   188 	} else {
   199 	} else {
   189 		$i = 0;
   200 		$i = 0;
   192 				$thelist .= $separator;
   203 				$thelist .= $separator;
   193 			switch ( strtolower( $parents ) ) {
   204 			switch ( strtolower( $parents ) ) {
   194 				case 'multiple':
   205 				case 'multiple':
   195 					if ( $category->parent )
   206 					if ( $category->parent )
   196 						$thelist .= get_category_parents( $category->parent, true, $separator );
   207 						$thelist .= get_category_parents( $category->parent, true, $separator );
   197 					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a>';
   208 					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>';
   198 					break;
   209 					break;
   199 				case 'single':
   210 				case 'single':
   200 					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>';
   211 					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>';
   201 					if ( $category->parent )
   212 					if ( $category->parent )
   202 						$thelist .= get_category_parents( $category->parent, false, $separator );
   213 						$thelist .= get_category_parents( $category->parent, false, $separator );
   203 					$thelist .= "$category->name</a>";
   214 					$thelist .= "$category->name</a>";
   204 					break;
   215 					break;
   205 				case '':
   216 				case '':
   206 				default:
   217 				default:
   207 					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a>';
   218 					$thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>';
   208 			}
   219 			}
   209 			++$i;
   220 			++$i;
   210 		}
   221 		}
   211 	}
   222 	}
       
   223 
       
   224 	/**
       
   225 	 * Filter the category or list of categories.
       
   226 	 *
       
   227 	 * @since 1.2.0
       
   228 	 *
       
   229 	 * @param array  $thelist   List of categories for the current post.
       
   230 	 * @param string $separator Separator used between the categories.
       
   231 	 * @param string $parents   How to display the category parents. Accepts 'multiple',
       
   232 	 *                          'single', or empty.
       
   233 	 */
   212 	return apply_filters( 'the_category', $thelist, $separator, $parents );
   234 	return apply_filters( 'the_category', $thelist, $separator, $parents );
   213 }
   235 }
   214 
   236 
   215 /**
   237 /**
   216  * Check if the current post in within any of the given categories.
   238  * Check if the current post in within any of the given categories.
   223  * Prior to v2.7, only one category could be compared: in_category( $single_category ).
   245  * Prior to v2.7, only one category could be compared: in_category( $single_category ).
   224  * Prior to v2.7, this function could only be used in the WordPress Loop.
   246  * Prior to v2.7, this function could only be used in the WordPress Loop.
   225  * As of 2.7, the function can be used anywhere if it is provided a post ID or post object.
   247  * As of 2.7, the function can be used anywhere if it is provided a post ID or post object.
   226  *
   248  *
   227  * @since 1.2.0
   249  * @since 1.2.0
   228  * @uses has_category()
       
   229  *
   250  *
   230  * @param int|string|array $category Category ID, name or slug, or array of said.
   251  * @param int|string|array $category Category ID, name or slug, or array of said.
   231  * @param int|object $post Optional. Post to check instead of the current post. (since 2.7.0)
   252  * @param int|object $post Optional. Post to check instead of the current post. (since 2.7.0)
   232  * @return bool True if the current post is in any of the given categories.
   253  * @return bool True if the current post is in any of the given categories.
   233  */
   254  */
   263 	return term_description( $category, 'category' );
   284 	return term_description( $category, 'category' );
   264 }
   285 }
   265 
   286 
   266 /**
   287 /**
   267  * Display or retrieve the HTML dropdown list of categories.
   288  * Display or retrieve the HTML dropdown list of categories.
   268  *
       
   269  * The list of arguments is below:
       
   270  *     'show_option_all' (string) - Text to display for showing all categories.
       
   271  *     'show_option_none' (string) - Text to display for showing no categories.
       
   272  *     'orderby' (string) default is 'ID' - What column to use for ordering the
       
   273  * categories.
       
   274  *     'order' (string) default is 'ASC' - What direction to order categories.
       
   275  *     'show_count' (bool|int) default is 0 - Whether to show how many posts are
       
   276  * in the category.
       
   277  *     'hide_empty' (bool|int) default is 1 - Whether to hide categories that
       
   278  * don't have any posts attached to them.
       
   279  *     'child_of' (int) default is 0 - See {@link get_categories()}.
       
   280  *     'exclude' (string) - See {@link get_categories()}.
       
   281  *     'echo' (bool|int) default is 1 - Whether to display or retrieve content.
       
   282  *     'depth' (int) - The max depth.
       
   283  *     'tab_index' (int) - Tab index for select element.
       
   284  *     'name' (string) - The name attribute value for select element.
       
   285  *     'id' (string) - The ID attribute value for select element. Defaults to name if omitted.
       
   286  *     'class' (string) - The class attribute value for select element.
       
   287  *     'selected' (int) - Which category ID is selected.
       
   288  *     'taxonomy' (string) - The name of the taxonomy to retrieve. Defaults to category.
       
   289  *
   289  *
   290  * The 'hierarchical' argument, which is disabled by default, will override the
   290  * The 'hierarchical' argument, which is disabled by default, will override the
   291  * depth argument, unless it is true. When the argument is false, it will
   291  * depth argument, unless it is true. When the argument is false, it will
   292  * display all of the categories. When it is enabled it will use the value in
   292  * display all of the categories. When it is enabled it will use the value in
   293  * the 'depth' argument.
   293  * the 'depth' argument.
   294  *
   294  *
   295  * @since 2.1.0
   295  * @since 2.1.0
   296  *
   296  * @since 4.2.0 Introduced the `value_field` argument.
   297  * @param string|array $args Optional. Override default arguments.
   297  *
       
   298  * @param string|array $args {
       
   299  *     Optional. Array or string of arguments to generate a categories drop-down element.
       
   300  *
       
   301  *     @type string       $show_option_all   Text to display for showing all categories. Default empty.
       
   302  *     @type string       $show_option_none  Text to display for showing no categories. Default empty.
       
   303  *     @type string       $option_none_value Value to use when no category is selected. Default empty.
       
   304  *     @type string       $orderby           Which column to use for ordering categories. See get_terms() for a list
       
   305  *                                           of accepted values. Default 'id' (term_id).
       
   306  *     @type string       $order             Whether to order terms in ascending or descending order. Accepts 'ASC'
       
   307  *                                           or 'DESC'. Default 'ASC'.
       
   308  *     @type bool         $pad_counts        See get_terms() for an argument description. Default false.
       
   309  *     @type bool|int     $show_count        Whether to include post counts. Accepts 0, 1, or their bool equivalents.
       
   310  *                                           Default 0.
       
   311  *     @type bool|int     $hide_empty        Whether to hide categories that don't have any posts. Accepts 0, 1, or
       
   312  *                                           their bool equivalents. Default 1.
       
   313  *     @type int          $child_of          Term ID to retrieve child terms of. See get_terms(). Default 0.
       
   314  *     @type array|string $exclude           Array or comma/space-separated string of term ids to exclude.
       
   315  *                                           If `$include` is non-empty, `$exclude` is ignored. Default empty array.
       
   316  *     @type bool|int     $echo              Whether to echo or return the generated markup. Accepts 0, 1, or their
       
   317  *                                           bool equivalents. Default 1.
       
   318  *     @type bool|int     $hierarchical      Whether to traverse the taxonomy hierarchy. Accepts 0, 1, or their bool
       
   319  *                                           equivalents. Default 0.
       
   320  *     @type int          $depth             Maximum depth. Default 0.
       
   321  *     @type int          $tab_index         Tab index for the select element. Default 0 (no tabindex).
       
   322  *     @type string       $name              Value for the 'name' attribute of the select element. Default 'cat'.
       
   323  *     @type string       $id                Value for the 'id' attribute of the select element. Defaults to the value
       
   324  *                                           of `$name`.
       
   325  *     @type string       $class             Value for the 'class' attribute of the select element. Default 'postform'.
       
   326  *     @type int|string   $selected          Value of the option that should be selected. Default 0.
       
   327  *     @type string       $value_field       Term field that should be used to populate the 'value' attribute
       
   328  *                                           of the option elements. Accepts any valid term field: 'term_id', 'name',
       
   329  *                                           'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description',
       
   330  *                                           'parent', 'count'. Default 'term_id'.
       
   331  *     @type string       $taxonomy          Name of the category to retrieve. Default 'category'.
       
   332  *     @type bool         $hide_if_empty     True to skip generating markup if no categories are found.
       
   333  *                                           Default false (create select element even if no categories are found).
       
   334  * }
   298  * @return string HTML content only if 'echo' argument is 0.
   335  * @return string HTML content only if 'echo' argument is 0.
   299  */
   336  */
   300 function wp_dropdown_categories( $args = '' ) {
   337 function wp_dropdown_categories( $args = '' ) {
   301 	$defaults = array(
   338 	$defaults = array(
   302 		'show_option_all' => '', 'show_option_none' => '',
   339 		'show_option_all' => '', 'show_option_none' => '',
   306 		'exclude' => '', 'echo' => 1,
   343 		'exclude' => '', 'echo' => 1,
   307 		'selected' => 0, 'hierarchical' => 0,
   344 		'selected' => 0, 'hierarchical' => 0,
   308 		'name' => 'cat', 'id' => '',
   345 		'name' => 'cat', 'id' => '',
   309 		'class' => 'postform', 'depth' => 0,
   346 		'class' => 'postform', 'depth' => 0,
   310 		'tab_index' => 0, 'taxonomy' => 'category',
   347 		'tab_index' => 0, 'taxonomy' => 'category',
   311 		'hide_if_empty' => false
   348 		'hide_if_empty' => false, 'option_none_value' => -1,
       
   349 		'value_field' => 'term_id',
   312 	);
   350 	);
   313 
   351 
   314 	$defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
   352 	$defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
   315 
   353 
   316 	// Back compat.
   354 	// Back compat.
   318 		_deprecated_argument( __FUNCTION__, '3.0', '' );
   356 		_deprecated_argument( __FUNCTION__, '3.0', '' );
   319 		$args['taxonomy'] = 'link_category';
   357 		$args['taxonomy'] = 'link_category';
   320 	}
   358 	}
   321 
   359 
   322 	$r = wp_parse_args( $args, $defaults );
   360 	$r = wp_parse_args( $args, $defaults );
   323 
   361 	$option_none_value = $r['option_none_value'];
   324 	if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
   362 
       
   363 	if ( ! isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
   325 		$r['pad_counts'] = true;
   364 		$r['pad_counts'] = true;
   326 	}
   365 	}
   327 
   366 
   328 	extract( $r );
   367 	$tab_index = $r['tab_index'];
   329 
   368 
   330 	$tab_index_attribute = '';
   369 	$tab_index_attribute = '';
   331 	if ( (int) $tab_index > 0 )
   370 	if ( (int) $tab_index > 0 ) {
   332 		$tab_index_attribute = " tabindex=\"$tab_index\"";
   371 		$tab_index_attribute = " tabindex=\"$tab_index\"";
   333 
   372 	}
   334 	$categories = get_terms( $taxonomy, $r );
   373 
   335 	$name = esc_attr( $name );
   374 	// Avoid clashes with the 'name' param of get_terms().
   336 	$class = esc_attr( $class );
   375 	$get_terms_args = $r;
   337 	$id = $id ? esc_attr( $id ) : $name;
   376 	unset( $get_terms_args['name'] );
   338 
   377 	$categories = get_terms( $r['taxonomy'], $get_terms_args );
   339 	if ( ! $r['hide_if_empty'] || ! empty($categories) )
   378 
       
   379 	$name = esc_attr( $r['name'] );
       
   380 	$class = esc_attr( $r['class'] );
       
   381 	$id = $r['id'] ? esc_attr( $r['id'] ) : $name;
       
   382 
       
   383 	if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) {
   340 		$output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
   384 		$output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
   341 	else
   385 	} else {
   342 		$output = '';
   386 		$output = '';
   343 
   387 	}
   344 	if ( empty($categories) && ! $r['hide_if_empty'] && !empty($show_option_none) ) {
   388 	if ( empty( $categories ) && ! $r['hide_if_empty'] && ! empty( $r['show_option_none'] ) ) {
   345 		$show_option_none = apply_filters( 'list_cats', $show_option_none );
   389 
   346 		$output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
   390 		/**
       
   391 		 * Filter a taxonomy drop-down display element.
       
   392 		 *
       
   393 		 * A variety of taxonomy drop-down display elements can be modified
       
   394 		 * just prior to display via this filter. Filterable arguments include
       
   395 		 * 'show_option_none', 'show_option_all', and various forms of the
       
   396 		 * term name.
       
   397 		 *
       
   398 		 * @since 1.2.0
       
   399 		 *
       
   400 		 * @see wp_dropdown_categories()
       
   401 		 *
       
   402 		 * @param string $element Taxonomy element to list.
       
   403 		 */
       
   404 		$show_option_none = apply_filters( 'list_cats', $r['show_option_none'] );
       
   405 		$output .= "\t<option value='" . esc_attr( $option_none_value ) . "' selected='selected'>$show_option_none</option>\n";
   347 	}
   406 	}
   348 
   407 
   349 	if ( ! empty( $categories ) ) {
   408 	if ( ! empty( $categories ) ) {
   350 
   409 
   351 		if ( $show_option_all ) {
   410 		if ( $r['show_option_all'] ) {
   352 			$show_option_all = apply_filters( 'list_cats', $show_option_all );
   411 
       
   412 			/** This filter is documented in wp-includes/category-template.php */
       
   413 			$show_option_all = apply_filters( 'list_cats', $r['show_option_all'] );
   353 			$selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';
   414 			$selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';
   354 			$output .= "\t<option value='0'$selected>$show_option_all</option>\n";
   415 			$output .= "\t<option value='0'$selected>$show_option_all</option>\n";
   355 		}
   416 		}
   356 
   417 
   357 		if ( $show_option_none ) {
   418 		if ( $r['show_option_none'] ) {
   358 			$show_option_none = apply_filters( 'list_cats', $show_option_none );
   419 
   359 			$selected = ( '-1' === strval($r['selected']) ) ? " selected='selected'" : '';
   420 			/** This filter is documented in wp-includes/category-template.php */
   360 			$output .= "\t<option value='-1'$selected>$show_option_none</option>\n";
   421 			$show_option_none = apply_filters( 'list_cats', $r['show_option_none'] );
   361 		}
   422 			$selected = selected( $option_none_value, $r['selected'], false );
   362 
   423 			$output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$selected>$show_option_none</option>\n";
   363 		if ( $hierarchical )
   424 		}
       
   425 
       
   426 		if ( $r['hierarchical'] ) {
   364 			$depth = $r['depth'];  // Walk the full depth.
   427 			$depth = $r['depth'];  // Walk the full depth.
   365 		else
   428 		} else {
   366 			$depth = -1; // Flat.
   429 			$depth = -1; // Flat.
   367 
   430 		}
   368 		$output .= walk_category_dropdown_tree( $categories, $depth, $r );
   431 		$output .= walk_category_dropdown_tree( $categories, $depth, $r );
   369 	}
   432 	}
   370 
   433 
   371 	if ( ! $r['hide_if_empty'] || ! empty($categories) )
   434 	if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) {
   372 		$output .= "</select>\n";
   435 		$output .= "</select>\n";
   373 
   436 	}
   374 	$output = apply_filters( 'wp_dropdown_cats', $output );
   437 	/**
   375 
   438 	 * Filter the taxonomy drop-down output.
   376 	if ( $echo )
   439 	 *
       
   440 	 * @since 2.1.0
       
   441 	 *
       
   442 	 * @param string $output HTML output.
       
   443 	 * @param array  $r      Arguments used to build the drop-down.
       
   444 	 */
       
   445 	$output = apply_filters( 'wp_dropdown_cats', $output, $r );
       
   446 
       
   447 	if ( $r['echo'] ) {
   377 		echo $output;
   448 		echo $output;
   378 
   449 	}
   379 	return $output;
   450 	return $output;
   380 }
   451 }
   381 
   452 
   382 /**
   453 /**
   383  * Display or retrieve the HTML list of categories.
   454  * Display or retrieve the HTML list of categories.
   390  *     'show_count' (bool|int) default is 0 - Whether to show how many posts are
   461  *     'show_count' (bool|int) default is 0 - Whether to show how many posts are
   391  * in the category.
   462  * in the category.
   392  *     'hide_empty' (bool|int) default is 1 - Whether to hide categories that
   463  *     'hide_empty' (bool|int) default is 1 - Whether to hide categories that
   393  * don't have any posts attached to them.
   464  * don't have any posts attached to them.
   394  *     'use_desc_for_title' (bool|int) default is 1 - Whether to use the
   465  *     'use_desc_for_title' (bool|int) default is 1 - Whether to use the
   395  * description instead of the category title.
   466  * category description as the title attribute.
   396  *     'feed' - See {@link get_categories()}.
   467  *     'feed' - See {@link get_categories()}.
   397  *     'feed_type' - See {@link get_categories()}.
   468  *     'feed_type' - See {@link get_categories()}.
   398  *     'feed_image' - See {@link get_categories()}.
   469  *     'feed_image' - See {@link get_categories()}.
   399  *     'child_of' (int) default is 0 - See {@link get_categories()}.
   470  *     'child_of' (int) default is 0 - See {@link get_categories()}.
   400  *     'exclude' (string) - See {@link get_categories()}.
   471  *     'exclude' (string) - See {@link get_categories()}.
   406  *     'depth' (int) - The max depth.
   477  *     'depth' (int) - The max depth.
   407  *
   478  *
   408  * @since 2.1.0
   479  * @since 2.1.0
   409  *
   480  *
   410  * @param string|array $args Optional. Override default arguments.
   481  * @param string|array $args Optional. Override default arguments.
   411  * @return string HTML content only if 'echo' argument is 0.
   482  * @return false|null|string HTML content only if 'echo' argument is 0.
   412  */
   483  */
   413 function wp_list_categories( $args = '' ) {
   484 function wp_list_categories( $args = '' ) {
   414 	$defaults = array(
   485 	$defaults = array(
   415 		'show_option_all' => '', 'show_option_none' => __('No categories'),
   486 		'show_option_all' => '', 'show_option_none' => __('No categories'),
   416 		'orderby' => 'name', 'order' => 'ASC',
   487 		'orderby' => 'name', 'order' => 'ASC',
   433 	if ( true == $r['hierarchical'] ) {
   504 	if ( true == $r['hierarchical'] ) {
   434 		$r['exclude_tree'] = $r['exclude'];
   505 		$r['exclude_tree'] = $r['exclude'];
   435 		$r['exclude'] = '';
   506 		$r['exclude'] = '';
   436 	}
   507 	}
   437 
   508 
   438 	if ( !isset( $r['class'] ) )
   509 	if ( ! isset( $r['class'] ) )
   439 		$r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];
   510 		$r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];
   440 
   511 
   441 	extract( $r );
   512 	if ( ! taxonomy_exists( $r['taxonomy'] ) ) {
   442 
       
   443 	if ( !taxonomy_exists($taxonomy) )
       
   444 		return false;
   513 		return false;
       
   514 	}
       
   515 
       
   516 	$show_option_all = $r['show_option_all'];
       
   517 	$show_option_none = $r['show_option_none'];
   445 
   518 
   446 	$categories = get_categories( $r );
   519 	$categories = get_categories( $r );
   447 
   520 
   448 	$output = '';
   521 	$output = '';
   449 	if ( $title_li && 'list' == $style )
   522 	if ( $r['title_li'] && 'list' == $r['style'] ) {
   450 			$output = '<li class="' . esc_attr( $class ) . '">' . $title_li . '<ul>';
   523 		$output = '<li class="' . esc_attr( $r['class'] ) . '">' . $r['title_li'] . '<ul>';
   451 
   524 	}
   452 	if ( empty( $categories ) ) {
   525 	if ( empty( $categories ) ) {
   453 		if ( ! empty( $show_option_none ) ) {
   526 		if ( ! empty( $show_option_none ) ) {
   454 			if ( 'list' == $style )
   527 			if ( 'list' == $r['style'] ) {
   455 				$output .= '<li>' . $show_option_none . '</li>';
   528 				$output .= '<li class="cat-item-none">' . $show_option_none . '</li>';
   456 			else
   529 			} else {
   457 				$output .= $show_option_none;
   530 				$output .= $show_option_none;
       
   531 			}
   458 		}
   532 		}
   459 	} else {
   533 	} else {
   460 		if ( ! empty( $show_option_all ) ) {
   534 		if ( ! empty( $show_option_all ) ) {
   461 			$posts_page = ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' );
   535 			$posts_page = ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' );
   462 			$posts_page = esc_url( $posts_page );
   536 			$posts_page = esc_url( $posts_page );
   463 			if ( 'list' == $style )
   537 			if ( 'list' == $r['style'] ) {
   464 				$output .= "<li><a href='$posts_page'>$show_option_all</a></li>";
   538 				$output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>";
   465 			else
   539 			} else {
   466 				$output .= "<a href='$posts_page'>$show_option_all</a>";
   540 				$output .= "<a href='$posts_page'>$show_option_all</a>";
       
   541 			}
   467 		}
   542 		}
   468 
   543 
   469 		if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) {
   544 		if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) {
   470 			$current_term_object = get_queried_object();
   545 			$current_term_object = get_queried_object();
   471 			if ( $current_term_object && $r['taxonomy'] === $current_term_object->taxonomy )
   546 			if ( $current_term_object && $r['taxonomy'] === $current_term_object->taxonomy ) {
   472 				$r['current_category'] = get_queried_object_id();
   547 				$r['current_category'] = get_queried_object_id();
   473 		}
   548 			}
   474 
   549 		}
   475 		if ( $hierarchical )
   550 
       
   551 		if ( $r['hierarchical'] ) {
   476 			$depth = $r['depth'];
   552 			$depth = $r['depth'];
   477 		else
   553 		} else {
   478 			$depth = -1; // Flat.
   554 			$depth = -1; // Flat.
   479 
   555 		}
   480 		$output .= walk_category_tree( $categories, $depth, $r );
   556 		$output .= walk_category_tree( $categories, $depth, $r );
   481 	}
   557 	}
   482 
   558 
   483 	if ( $title_li && 'list' == $style )
   559 	if ( $r['title_li'] && 'list' == $r['style'] )
   484 		$output .= '</ul></li>';
   560 		$output .= '</ul></li>';
   485 
   561 
   486 	$output = apply_filters( 'wp_list_categories', $output, $args );
   562 	/**
   487 
   563 	 * Filter the HTML output of a taxonomy list.
   488 	if ( $echo )
   564 	 *
   489 		echo $output;
   565 	 * @since 2.1.0
   490 	else
   566 	 *
   491 		return $output;
   567 	 * @param string $output HTML output.
       
   568 	 * @param array  $args   An array of taxonomy-listing arguments.
       
   569 	 */
       
   570 	$html = apply_filters( 'wp_list_categories', $output, $args );
       
   571 
       
   572 	if ( $r['echo'] ) {
       
   573 		echo $html;
       
   574 	} else {
       
   575 		return $html;
       
   576 	}
   492 }
   577 }
   493 
   578 
   494 /**
   579 /**
   495  * Display tag cloud.
   580  * Display tag cloud.
   496  *
   581  *
   505  * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'.
   590  * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'.
   506  *
   591  *
   507  * The 'number' argument is how many tags to return. By default, the limit will
   592  * The 'number' argument is how many tags to return. By default, the limit will
   508  * be to return the top 45 tags in the tag cloud list.
   593  * be to return the top 45 tags in the tag cloud list.
   509  *
   594  *
   510  * The 'topic_count_text_callback' argument is a function, which, given the count
   595  * The 'topic_count_text' argument is a nooped plural from _n_noop() to generate the
   511  * of the posts  with that tag, returns a text for the tooltip of the tag link.
   596  * text for the tooltip of the tag link.
       
   597  *
       
   598  * The 'topic_count_text_callback' argument is a function, which given the count
       
   599  * of the posts with that tag returns a text for the tooltip of the tag link.
       
   600  *
       
   601  * The 'post_type' argument is used only when 'link' is set to 'edit'. It determines the post_type
       
   602  * passed to edit.php for the popular tags edit links.
   512  *
   603  *
   513  * The 'exclude' and 'include' arguments are used for the {@link get_tags()}
   604  * The 'exclude' and 'include' arguments are used for the {@link get_tags()}
   514  * function. Only one should be used, because only one will be used and the
   605  * function. Only one should be used, because only one will be used and the
   515  * other ignored, if they are both set.
   606  * other ignored, if they are both set.
   516  *
   607  *
   517  * @since 2.3.0
   608  * @since 2.3.0
   518  *
   609  *
   519  * @param array|string $args Optional. Override default arguments.
   610  * @param array|string|null $args Optional. Override default arguments.
   520  * @return array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument.
   611  * @return null|false Generated tag cloud, only if no failures and 'array' is set for the 'format' argument.
   521  */
   612  */
   522 function wp_tag_cloud( $args = '' ) {
   613 function wp_tag_cloud( $args = '' ) {
   523 	$defaults = array(
   614 	$defaults = array(
   524 		'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
   615 		'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
   525 		'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
   616 		'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
   526 		'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true
   617 		'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'post_type' => '', 'echo' => true
   527 	);
   618 	);
   528 	$args = wp_parse_args( $args, $defaults );
   619 	$args = wp_parse_args( $args, $defaults );
   529 
   620 
   530 	$tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
   621 	$tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
   531 
   622 
   532 	if ( empty( $tags ) || is_wp_error( $tags ) )
   623 	if ( empty( $tags ) || is_wp_error( $tags ) )
   533 		return;
   624 		return;
   534 
   625 
   535 	foreach ( $tags as $key => $tag ) {
   626 	foreach ( $tags as $key => $tag ) {
   536 		if ( 'edit' == $args['link'] )
   627 		if ( 'edit' == $args['link'] )
   537 			$link = get_edit_tag_link( $tag->term_id, $tag->taxonomy );
   628 			$link = get_edit_term_link( $tag->term_id, $tag->taxonomy, $args['post_type'] );
   538 		else
   629 		else
   539 			$link = get_term_link( intval($tag->term_id), $tag->taxonomy );
   630 			$link = get_term_link( intval($tag->term_id), $tag->taxonomy );
   540 		if ( is_wp_error( $link ) )
   631 		if ( is_wp_error( $link ) )
   541 			return false;
   632 			return false;
   542 
   633 
   544 		$tags[ $key ]->id = $tag->term_id;
   635 		$tags[ $key ]->id = $tag->term_id;
   545 	}
   636 	}
   546 
   637 
   547 	$return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
   638 	$return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
   548 
   639 
       
   640 	/**
       
   641 	 * Filter the tag cloud output.
       
   642 	 *
       
   643 	 * @since 2.3.0
       
   644 	 *
       
   645 	 * @param string $return HTML output of the tag cloud.
       
   646 	 * @param array  $args   An array of tag cloud arguments.
       
   647 	 */
   549 	$return = apply_filters( 'wp_tag_cloud', $return, $args );
   648 	$return = apply_filters( 'wp_tag_cloud', $return, $args );
   550 
   649 
   551 	if ( 'array' == $args['format'] || empty($args['echo']) )
   650 	if ( 'array' == $args['format'] || empty($args['echo']) )
   552 		return $return;
   651 		return $return;
   553 
   652 
   554 	echo $return;
   653 	echo $return;
   555 }
       
   556 
       
   557 /**
       
   558  * Default text for tooltip for tag links
       
   559  *
       
   560  * @param integer $count number of posts with that tag
       
   561  * @return string text for the tooltip of a tag link.
       
   562  */
       
   563 function default_topic_count_text( $count ) {
       
   564 	return sprintf( _n('%s topic', '%s topics', $count), number_format_i18n( $count ) );
       
   565 }
   654 }
   566 
   655 
   567 /**
   656 /**
   568  * Default topic count scaling for tag links
   657  * Default topic count scaling for tag links
   569  *
   658  *
   593  * 'RAND'.
   682  * 'RAND'.
   594  *
   683  *
   595  * The 'number' argument is how many tags to return. By default, the limit will
   684  * The 'number' argument is how many tags to return. By default, the limit will
   596  * be to return the entire tag cloud list.
   685  * be to return the entire tag cloud list.
   597  *
   686  *
       
   687  * The 'topic_count_text' argument is a nooped plural from _n_noop() to generate the
       
   688  * text for the tooltip of the tag link.
       
   689  *
   598  * The 'topic_count_text_callback' argument is a function, which given the count
   690  * The 'topic_count_text_callback' argument is a function, which given the count
   599  * of the posts  with that tag returns a text for the tooltip of the tag link.
   691  * of the posts with that tag returns a text for the tooltip of the tag link.
   600  *
   692  *
   601  * @todo Complete functionality.
   693  * @todo Complete functionality.
   602  * @since 2.3.0
   694  * @since 2.3.0
   603  *
   695  *
   604  * @param array $tags List of tags.
   696  * @param array $tags List of tags.
   605  * @param string|array $args Optional, override default arguments.
   697  * @param string|array $args Optional, override default arguments.
   606  * @return string
   698  * @return string|array Tag cloud as a string or an array, depending on 'format' argument.
   607  */
   699  */
   608 function wp_generate_tag_cloud( $tags, $args = '' ) {
   700 function wp_generate_tag_cloud( $tags, $args = '' ) {
   609 	$defaults = array(
   701 	$defaults = array(
   610 		'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0,
   702 		'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0,
   611 		'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
   703 		'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
   612 		'topic_count_text_callback' => 'default_topic_count_text',
   704 		'topic_count_text' => null, 'topic_count_text_callback' => null,
   613 		'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1,
   705 		'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1,
   614 	);
   706 	);
   615 
   707 
   616 	if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
       
   617 		$body = 'return sprintf (
       
   618 			_n(' . var_export($args['single_text'], true) . ', ' . var_export($args['multiple_text'], true) . ', $count),
       
   619 			number_format_i18n( $count ));';
       
   620 		$args['topic_count_text_callback'] = create_function('$count', $body);
       
   621 	}
       
   622 
       
   623 	$args = wp_parse_args( $args, $defaults );
   708 	$args = wp_parse_args( $args, $defaults );
   624 	extract( $args );
   709 
   625 
   710 	$return = ( 'array' === $args['format'] ) ? array() : '';
   626 	if ( empty( $tags ) )
   711 
   627 		return;
   712 	if ( empty( $tags ) ) {
   628 
   713 		return $return;
       
   714 	}
       
   715 
       
   716 	// Juggle topic count tooltips:
       
   717 	if ( isset( $args['topic_count_text'] ) ) {
       
   718 		// First look for nooped plural support via topic_count_text.
       
   719 		$translate_nooped_plural = $args['topic_count_text'];
       
   720 	} elseif ( ! empty( $args['topic_count_text_callback'] ) ) {
       
   721 		// Look for the alternative callback style. Ignore the previous default.
       
   722 		if ( $args['topic_count_text_callback'] === 'default_topic_count_text' ) {
       
   723 			$translate_nooped_plural = _n_noop( '%s topic', '%s topics' );
       
   724 		} else {
       
   725 			$translate_nooped_plural = false;
       
   726 		}
       
   727 	} elseif ( isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
       
   728 		// If no callback exists, look for the old-style single_text and multiple_text arguments.
       
   729 		$translate_nooped_plural = _n_noop( $args['single_text'], $args['multiple_text'] );
       
   730 	} else {
       
   731 		// This is the default for when no callback, plural, or argument is passed in.
       
   732 		$translate_nooped_plural = _n_noop( '%s topic', '%s topics' );
       
   733 	}
       
   734 
       
   735 	/**
       
   736 	 * Filter how the items in a tag cloud are sorted.
       
   737 	 *
       
   738 	 * @since 2.8.0
       
   739 	 *
       
   740 	 * @param array $tags Ordered array of terms.
       
   741 	 * @param array $args An array of tag cloud arguments.
       
   742 	 */
   629 	$tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args );
   743 	$tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args );
   630 	if ( $tags_sorted != $tags  ) { // the tags have been sorted by a plugin
   744 	if ( empty( $tags_sorted ) ) {
       
   745 		return $return;
       
   746 	}
       
   747 
       
   748 	if ( $tags_sorted !== $tags ) {
   631 		$tags = $tags_sorted;
   749 		$tags = $tags_sorted;
   632 		unset($tags_sorted);
   750 		unset( $tags_sorted );
   633 	} else {
   751 	} else {
   634 		if ( 'RAND' == $order ) {
   752 		if ( 'RAND' === $args['order'] ) {
   635 			shuffle($tags);
   753 			shuffle( $tags );
   636 		} else {
   754 		} else {
   637 			// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
   755 			// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
   638 			if ( 'name' == $orderby )
   756 			if ( 'name' === $args['orderby'] ) {
   639 				uasort( $tags, '_wp_object_name_sort_cb' );
   757 				uasort( $tags, '_wp_object_name_sort_cb' );
   640 			else
   758 			} else {
   641 				uasort( $tags, '_wp_object_count_sort_cb' );
   759 				uasort( $tags, '_wp_object_count_sort_cb' );
   642 
   760 			}
   643 			if ( 'DESC' == $order )
   761 
       
   762 			if ( 'DESC' === $args['order'] ) {
   644 				$tags = array_reverse( $tags, true );
   763 				$tags = array_reverse( $tags, true );
   645 		}
   764 			}
   646 	}
   765 		}
   647 
   766 	}
   648 	if ( $number > 0 )
   767 
   649 		$tags = array_slice($tags, 0, $number);
   768 	if ( $args['number'] > 0 )
       
   769 		$tags = array_slice( $tags, 0, $args['number'] );
   650 
   770 
   651 	$counts = array();
   771 	$counts = array();
   652 	$real_counts = array(); // For the alt tag
   772 	$real_counts = array(); // For the alt tag
   653 	foreach ( (array) $tags as $key => $tag ) {
   773 	foreach ( (array) $tags as $key => $tag ) {
   654 		$real_counts[ $key ] = $tag->count;
   774 		$real_counts[ $key ] = $tag->count;
   655 		$counts[ $key ] = $topic_count_scale_callback($tag->count);
   775 		$counts[ $key ] = call_user_func( $args['topic_count_scale_callback'], $tag->count );
   656 	}
   776 	}
   657 
   777 
   658 	$min_count = min( $counts );
   778 	$min_count = min( $counts );
   659 	$spread = max( $counts ) - $min_count;
   779 	$spread = max( $counts ) - $min_count;
   660 	if ( $spread <= 0 )
   780 	if ( $spread <= 0 )
   661 		$spread = 1;
   781 		$spread = 1;
   662 	$font_spread = $largest - $smallest;
   782 	$font_spread = $args['largest'] - $args['smallest'];
   663 	if ( $font_spread < 0 )
   783 	if ( $font_spread < 0 )
   664 		$font_spread = 1;
   784 		$font_spread = 1;
   665 	$font_step = $font_spread / $spread;
   785 	$font_step = $font_spread / $spread;
   666 
   786 
   667 	$a = array();
   787 	$a = array();
   670 		$count = $counts[ $key ];
   790 		$count = $counts[ $key ];
   671 		$real_count = $real_counts[ $key ];
   791 		$real_count = $real_counts[ $key ];
   672 		$tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#';
   792 		$tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#';
   673 		$tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;
   793 		$tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;
   674 		$tag_name = $tags[ $key ]->name;
   794 		$tag_name = $tags[ $key ]->name;
   675 		$a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( call_user_func( $topic_count_text_callback, $real_count, $tag, $args ) ) . "' style='font-size: " .
   795 
   676 			str_replace( ',', '.', ( $smallest + ( ( $count - $min_count ) * $font_step ) ) )
   796 		if ( $translate_nooped_plural ) {
   677 			. "$unit;'>$tag_name</a>";
   797 			$title_attribute = sprintf( translate_nooped_plural( $translate_nooped_plural, $real_count ), number_format_i18n( $real_count ) );
   678 	}
   798 		} else {
   679 
   799 			$title_attribute = call_user_func( $args['topic_count_text_callback'], $real_count, $tag, $args );
   680 	switch ( $format ) :
   800 		}
   681 	case 'array' :
   801 
   682 		$return =& $a;
   802 		$a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( $title_attribute ) . "' style='font-size: " .
   683 		break;
   803 			str_replace( ',', '.', ( $args['smallest'] + ( ( $count - $min_count ) * $font_step ) ) )
   684 	case 'list' :
   804 			. $args['unit'] . ";'>$tag_name</a>";
   685 		$return = "<ul class='wp-tag-cloud'>\n\t<li>";
   805 	}
   686 		$return .= join( "</li>\n\t<li>", $a );
   806 
   687 		$return .= "</li>\n</ul>\n";
   807 	switch ( $args['format'] ) {
   688 		break;
   808 		case 'array' :
   689 	default :
   809 			$return =& $a;
   690 		$return = join( $separator, $a );
   810 			break;
   691 		break;
   811 		case 'list' :
   692 	endswitch;
   812 			$return = "<ul class='wp-tag-cloud'>\n\t<li>";
   693 
   813 			$return .= join( "</li>\n\t<li>", $a );
   694 	if ( $filter )
   814 			$return .= "</li>\n</ul>\n";
       
   815 			break;
       
   816 		default :
       
   817 			$return = join( $args['separator'], $a );
       
   818 			break;
       
   819 	}
       
   820 
       
   821 	if ( $args['filter'] ) {
       
   822 		/**
       
   823 		 * Filter the generated output of a tag cloud.
       
   824 		 *
       
   825 		 * The filter is only evaluated if a true value is passed
       
   826 		 * to the $filter argument in wp_generate_tag_cloud().
       
   827 		 *
       
   828 		 * @since 2.3.0
       
   829 		 *
       
   830 		 * @see wp_generate_tag_cloud()
       
   831 		 *
       
   832 		 * @param array|string $return String containing the generated HTML tag cloud output
       
   833 		 *                             or an array of tag links if the 'format' argument
       
   834 		 *                             equals 'array'.
       
   835 		 * @param array        $tags   An array of terms used in the tag cloud.
       
   836 		 * @param array        $args   An array of wp_generate_tag_cloud() arguments.
       
   837 		 */
   695 		return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args );
   838 		return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args );
       
   839 	}
       
   840 
   696 	else
   841 	else
   697 		return $return;
   842 		return $return;
   698 }
   843 }
   699 
   844 
   700 /**
   845 /**
   729  * @see Walker_Category::walk() for parameters and return description.
   874  * @see Walker_Category::walk() for parameters and return description.
   730  */
   875  */
   731 function walk_category_tree() {
   876 function walk_category_tree() {
   732 	$args = func_get_args();
   877 	$args = func_get_args();
   733 	// the user's options are the third parameter
   878 	// the user's options are the third parameter
   734 	if ( empty($args[2]['walker']) || !is_a($args[2]['walker'], 'Walker') )
   879 	if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) {
   735 		$walker = new Walker_Category;
   880 		$walker = new Walker_Category;
   736 	else
   881 	} else {
   737 		$walker = $args[2]['walker'];
   882 		$walker = $args[2]['walker'];
   738 
   883 	}
   739 	return call_user_func_array(array( &$walker, 'walk' ), $args );
   884 	return call_user_func_array(array( &$walker, 'walk' ), $args );
   740 }
   885 }
   741 
   886 
   742 /**
   887 /**
   743  * Retrieve HTML dropdown (select) content for category list.
   888  * Retrieve HTML dropdown (select) content for category list.
   770 	 *
   915 	 *
   771 	 * @see Walker::$tree_type
   916 	 * @see Walker::$tree_type
   772 	 * @since 2.1.0
   917 	 * @since 2.1.0
   773 	 * @var string
   918 	 * @var string
   774 	 */
   919 	 */
   775 	var $tree_type = 'category';
   920 	public $tree_type = 'category';
   776 
   921 
   777 	/**
   922 	/**
   778 	 * Database fields to use.
   923 	 * Database fields to use.
   779 	 *
   924 	 *
   780 	 * @see Walker::$db_fields
   925 	 * @see Walker::$db_fields
   781 	 * @since 2.1.0
   926 	 * @since 2.1.0
   782 	 * @todo Decouple this
   927 	 * @todo Decouple this
   783 	 * @var array
   928 	 * @var array
   784 	 */
   929 	 */
   785 	var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
   930 	public $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
   786 
   931 
   787 	/**
   932 	/**
   788 	 * Starts the list before the elements are added.
   933 	 * Starts the list before the elements are added.
   789 	 *
   934 	 *
   790 	 * @see Walker::start_lvl()
   935 	 * @see Walker::start_lvl()
   794 	 * @param string $output Passed by reference. Used to append additional content.
   939 	 * @param string $output Passed by reference. Used to append additional content.
   795 	 * @param int    $depth  Depth of category. Used for tab indentation.
   940 	 * @param int    $depth  Depth of category. Used for tab indentation.
   796 	 * @param array  $args   An array of arguments. Will only append content if style argument value is 'list'.
   941 	 * @param array  $args   An array of arguments. Will only append content if style argument value is 'list'.
   797 	 *                       @see wp_list_categories()
   942 	 *                       @see wp_list_categories()
   798 	 */
   943 	 */
   799 	function start_lvl( &$output, $depth = 0, $args = array() ) {
   944 	public function start_lvl( &$output, $depth = 0, $args = array() ) {
   800 		if ( 'list' != $args['style'] )
   945 		if ( 'list' != $args['style'] )
   801 			return;
   946 			return;
   802 
   947 
   803 		$indent = str_repeat("\t", $depth);
   948 		$indent = str_repeat("\t", $depth);
   804 		$output .= "$indent<ul class='children'>\n";
   949 		$output .= "$indent<ul class='children'>\n";
   814 	 * @param string $output Passed by reference. Used to append additional content.
   959 	 * @param string $output Passed by reference. Used to append additional content.
   815 	 * @param int    $depth  Depth of category. Used for tab indentation.
   960 	 * @param int    $depth  Depth of category. Used for tab indentation.
   816 	 * @param array  $args   An array of arguments. Will only append content if style argument value is 'list'.
   961 	 * @param array  $args   An array of arguments. Will only append content if style argument value is 'list'.
   817 	 *                       @wsee wp_list_categories()
   962 	 *                       @wsee wp_list_categories()
   818 	 */
   963 	 */
   819 	function end_lvl( &$output, $depth = 0, $args = array() ) {
   964 	public function end_lvl( &$output, $depth = 0, $args = array() ) {
   820 		if ( 'list' != $args['style'] )
   965 		if ( 'list' != $args['style'] )
   821 			return;
   966 			return;
   822 
   967 
   823 		$indent = str_repeat("\t", $depth);
   968 		$indent = str_repeat("\t", $depth);
   824 		$output .= "$indent</ul>\n";
   969 		$output .= "$indent</ul>\n";
   835 	 * @param object $category Category data object.
   980 	 * @param object $category Category data object.
   836 	 * @param int    $depth    Depth of category in reference to parents. Default 0.
   981 	 * @param int    $depth    Depth of category in reference to parents. Default 0.
   837 	 * @param array  $args     An array of arguments. @see wp_list_categories()
   982 	 * @param array  $args     An array of arguments. @see wp_list_categories()
   838 	 * @param int    $id       ID of the current category.
   983 	 * @param int    $id       ID of the current category.
   839 	 */
   984 	 */
   840 	function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
   985 	public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
   841 		extract($args);
   986 		/** This filter is documented in wp-includes/category-template.php */
   842 
   987 		$cat_name = apply_filters(
   843 		$cat_name = esc_attr( $category->name );
   988 			'list_cats',
   844 		$cat_name = apply_filters( 'list_cats', $cat_name, $category );
   989 			esc_attr( $category->name ),
   845 		$link = '<a href="' . esc_url( get_term_link($category) ) . '" ';
   990 			$category
   846 		if ( $use_desc_for_title == 0 || empty($category->description) )
   991 		);
   847 			$link .= 'title="' . esc_attr( sprintf(__( 'View all posts filed under %s' ), $cat_name) ) . '"';
   992 
   848 		else
   993 		// Don't generate an element if the category name is empty.
       
   994 		if ( ! $cat_name ) {
       
   995 			return;
       
   996 		}
       
   997 
       
   998 		$link = '<a href="' . esc_url( get_term_link( $category ) ) . '" ';
       
   999 		if ( $args['use_desc_for_title'] && ! empty( $category->description ) ) {
       
  1000 			/**
       
  1001 			 * Filter the category description for display.
       
  1002 			 *
       
  1003 			 * @since 1.2.0
       
  1004 			 *
       
  1005 			 * @param string $description Category description.
       
  1006 			 * @param object $category    Category object.
       
  1007 			 */
   849 			$link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
  1008 			$link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
       
  1009 		}
       
  1010 
   850 		$link .= '>';
  1011 		$link .= '>';
   851 		$link .= $cat_name . '</a>';
  1012 		$link .= $cat_name . '</a>';
   852 
  1013 
   853 		if ( !empty($feed_image) || !empty($feed) ) {
  1014 		if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) {
   854 			$link .= ' ';
  1015 			$link .= ' ';
   855 
  1016 
   856 			if ( empty($feed_image) )
  1017 			if ( empty( $args['feed_image'] ) ) {
   857 				$link .= '(';
  1018 				$link .= '(';
   858 
  1019 			}
   859 			$link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $feed_type ) ) . '"';
  1020 
   860 
  1021 			$link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $args['feed_type'] ) ) . '"';
   861 			if ( empty($feed) ) {
  1022 
       
  1023 			if ( empty( $args['feed'] ) ) {
   862 				$alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
  1024 				$alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
   863 			} else {
  1025 			} else {
   864 				$title = ' title="' . $feed . '"';
  1026 				$alt = ' alt="' . $args['feed'] . '"';
   865 				$alt = ' alt="' . $feed . '"';
  1027 				$name = $args['feed'];
   866 				$name = $feed;
  1028 				$link .= empty( $args['title'] ) ? '' : $args['title'];
   867 				$link .= $title;
       
   868 			}
  1029 			}
   869 
  1030 
   870 			$link .= '>';
  1031 			$link .= '>';
   871 
  1032 
   872 			if ( empty($feed_image) )
  1033 			if ( empty( $args['feed_image'] ) ) {
   873 				$link .= $name;
  1034 				$link .= $name;
   874 			else
  1035 			} else {
   875 				$link .= "<img src='$feed_image'$alt$title" . ' />';
  1036 				$link .= "<img src='" . $args['feed_image'] . "'$alt" . ' />';
   876 
  1037 			}
   877 			$link .= '</a>';
  1038 			$link .= '</a>';
   878 
  1039 
   879 			if ( empty($feed_image) )
  1040 			if ( empty( $args['feed_image'] ) ) {
   880 				$link .= ')';
  1041 				$link .= ')';
   881 		}
  1042 			}
   882 
  1043 		}
   883 		if ( !empty($show_count) )
  1044 
   884 			$link .= ' (' . intval($category->count) . ')';
  1045 		if ( ! empty( $args['show_count'] ) ) {
   885 
  1046 			$link .= ' (' . number_format_i18n( $category->count ) . ')';
       
  1047 		}
   886 		if ( 'list' == $args['style'] ) {
  1048 		if ( 'list' == $args['style'] ) {
   887 			$output .= "\t<li";
  1049 			$output .= "\t<li";
   888 			$class = 'cat-item cat-item-' . $category->term_id;
  1050 			$css_classes = array(
   889 			if ( !empty($current_category) ) {
  1051 				'cat-item',
   890 				$_current_category = get_term( $current_category, $category->taxonomy );
  1052 				'cat-item-' . $category->term_id,
   891 				if ( $category->term_id == $current_category )
  1053 			);
   892 					$class .=  ' current-cat';
  1054 
   893 				elseif ( $category->term_id == $_current_category->parent )
  1055 			if ( ! empty( $args['current_category'] ) ) {
   894 					$class .=  ' current-cat-parent';
  1056 				$_current_category = get_term( $args['current_category'], $category->taxonomy );
       
  1057 				if ( $category->term_id == $args['current_category'] ) {
       
  1058 					$css_classes[] = 'current-cat';
       
  1059 				} elseif ( $category->term_id == $_current_category->parent ) {
       
  1060 					$css_classes[] = 'current-cat-parent';
       
  1061 				}
   895 			}
  1062 			}
   896 			$output .=  ' class="' . $class . '"';
  1063 
       
  1064 			/**
       
  1065 			 * Filter the list of CSS classes to include with each category in the list.
       
  1066 			 *
       
  1067 			 * @since 4.2.0
       
  1068 			 *
       
  1069 			 * @see wp_list_categories()
       
  1070 			 *
       
  1071 			 * @param array  $css_classes An array of CSS classes to be applied to each list item.
       
  1072 			 * @param object $category    Category data object.
       
  1073 			 * @param int    $depth       Depth of page, used for padding.
       
  1074 			 * @param array  $args        An array of wp_list_categories() arguments.
       
  1075 			 */
       
  1076 			$css_classes = implode( ' ', apply_filters( 'category_css_class', $css_classes, $category, $depth, $args ) );
       
  1077 
       
  1078 			$output .=  ' class="' . $css_classes . '"';
   897 			$output .= ">$link\n";
  1079 			$output .= ">$link\n";
   898 		} else {
  1080 		} else {
   899 			$output .= "\t$link<br />\n";
  1081 			$output .= "\t$link<br />\n";
   900 		}
  1082 		}
   901 	}
  1083 	}
   910 	 * @param string $output Passed by reference. Used to append additional content.
  1092 	 * @param string $output Passed by reference. Used to append additional content.
   911 	 * @param object $page   Not used.
  1093 	 * @param object $page   Not used.
   912 	 * @param int    $depth  Depth of category. Not used.
  1094 	 * @param int    $depth  Depth of category. Not used.
   913 	 * @param array  $args   An array of arguments. Only uses 'list' for whether should append to output. @see wp_list_categories()
  1095 	 * @param array  $args   An array of arguments. Only uses 'list' for whether should append to output. @see wp_list_categories()
   914 	 */
  1096 	 */
   915 	function end_el( &$output, $page, $depth = 0, $args = array() ) {
  1097 	public function end_el( &$output, $page, $depth = 0, $args = array() ) {
   916 		if ( 'list' != $args['style'] )
  1098 		if ( 'list' != $args['style'] )
   917 			return;
  1099 			return;
   918 
  1100 
   919 		$output .= "</li>\n";
  1101 		$output .= "</li>\n";
   920 	}
  1102 	}
   932 	/**
  1114 	/**
   933 	 * @see Walker::$tree_type
  1115 	 * @see Walker::$tree_type
   934 	 * @since 2.1.0
  1116 	 * @since 2.1.0
   935 	 * @var string
  1117 	 * @var string
   936 	 */
  1118 	 */
   937 	var $tree_type = 'category';
  1119 	public $tree_type = 'category';
   938 
  1120 
   939 	/**
  1121 	/**
   940 	 * @see Walker::$db_fields
  1122 	 * @see Walker::$db_fields
   941 	 * @since 2.1.0
  1123 	 * @since 2.1.0
   942 	 * @todo Decouple this
  1124 	 * @todo Decouple this
   943 	 * @var array
  1125 	 * @var array
   944 	 */
  1126 	 */
   945 	var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
  1127 	public $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
   946 
  1128 
   947 	/**
  1129 	/**
   948 	 * Start the element output.
  1130 	 * Start the element output.
   949 	 *
  1131 	 *
   950 	 * @see Walker::start_el()
  1132 	 * @see Walker::start_el()
   951 	 * @since 2.1.0
  1133 	 * @since 2.1.0
   952 	 *
  1134 	 *
   953 	 * @param string $output   Passed by reference. Used to append additional content.
  1135 	 * @param string $output   Passed by reference. Used to append additional content.
   954 	 * @param object $category Category data object.
  1136 	 * @param object $category Category data object.
   955 	 * @param int    $depth    Depth of category. Used for padding.
  1137 	 * @param int    $depth    Depth of category. Used for padding.
   956 	 * @param array  $args     Uses 'selected' and 'show_count' keys, if they exist. @see wp_dropdown_categories()
  1138 	 * @param array  $args     Uses 'selected', 'show_count', and 'value_field' keys, if they exist.
   957 	 */
  1139 	 *                         See {@see wp_dropdown_categories()}.
   958 	function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
  1140 	 */
       
  1141 	public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
   959 		$pad = str_repeat('&nbsp;', $depth * 3);
  1142 		$pad = str_repeat('&nbsp;', $depth * 3);
   960 
  1143 
   961 		$cat_name = apply_filters('list_cats', $category->name, $category);
  1144 		/** This filter is documented in wp-includes/category-template.php */
   962 		$output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\"";
  1145 		$cat_name = apply_filters( 'list_cats', $category->name, $category );
       
  1146 
       
  1147 		if ( ! isset( $args['value_field'] ) || ! isset( $category->{$args['value_field']} ) ) {
       
  1148 			$args['value_field'] = 'term_id';
       
  1149 		}
       
  1150 
       
  1151 		$output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $category->{$args['value_field']} ) . "\"";
       
  1152 
   963 		if ( $category->term_id == $args['selected'] )
  1153 		if ( $category->term_id == $args['selected'] )
   964 			$output .= ' selected="selected"';
  1154 			$output .= ' selected="selected"';
   965 		$output .= '>';
  1155 		$output .= '>';
   966 		$output .= $pad.$cat_name;
  1156 		$output .= $pad.$cat_name;
   967 		if ( $args['show_count'] )
  1157 		if ( $args['show_count'] )
   968 			$output .= '&nbsp;&nbsp;('. $category->count .')';
  1158 			$output .= '&nbsp;&nbsp;('. number_format_i18n( $category->count ) .')';
   969 		$output .= "</option>\n";
  1159 		$output .= "</option>\n";
   970 	}
  1160 	}
   971 }
  1161 }
   972 
  1162 
   973 //
  1163 //
   997 
  1187 
   998 /**
  1188 /**
   999  * Retrieve the tags for a post.
  1189  * Retrieve the tags for a post.
  1000  *
  1190  *
  1001  * @since 2.3.0
  1191  * @since 2.3.0
  1002  * @uses apply_filters() Calls 'get_the_tags' filter on the list of post tags.
       
  1003  *
  1192  *
  1004  * @param int $id Post ID.
  1193  * @param int $id Post ID.
  1005  * @return array|bool Array of tag objects on success, false on failure.
  1194  * @return array|bool Array of tag objects on success, false on failure.
  1006  */
  1195  */
  1007 function get_the_tags( $id = 0 ) {
  1196 function get_the_tags( $id = 0 ) {
       
  1197 
       
  1198 	/**
       
  1199 	 * Filter the array of tags for the given post.
       
  1200 	 *
       
  1201 	 * @since 2.3.0
       
  1202 	 *
       
  1203 	 * @see get_the_terms()
       
  1204 	 *
       
  1205 	 * @param array $terms An array of tags for the given post.
       
  1206 	 */
  1008 	return apply_filters( 'get_the_tags', get_the_terms( $id, 'post_tag' ) );
  1207 	return apply_filters( 'get_the_tags', get_the_terms( $id, 'post_tag' ) );
  1009 }
  1208 }
  1010 
  1209 
  1011 /**
  1210 /**
  1012  * Retrieve the tags for a post formatted as a string.
  1211  * Retrieve the tags for a post formatted as a string.
  1013  *
  1212  *
  1014  * @since 2.3.0
  1213  * @since 2.3.0
  1015  * @uses apply_filters() Calls 'the_tags' filter on string list of tags.
       
  1016  *
  1214  *
  1017  * @param string $before Optional. Before tags.
  1215  * @param string $before Optional. Before tags.
  1018  * @param string $sep Optional. Between tags.
  1216  * @param string $sep Optional. Between tags.
  1019  * @param string $after Optional. After tags.
  1217  * @param string $after Optional. After tags.
  1020  * @param int $id Optional. Post ID. Defaults to the current post.
  1218  * @param int $id Optional. Post ID. Defaults to the current post.
  1021  * @return string|bool|WP_Error A list of tags on success, false or WP_Error on failure.
  1219  * @return string|bool|WP_Error A list of tags on success, false if there are no terms, WP_Error on failure.
  1022  */
  1220  */
  1023 function get_the_tag_list( $before = '', $sep = '', $after = '', $id = 0 ) {
  1221 function get_the_tag_list( $before = '', $sep = '', $after = '', $id = 0 ) {
       
  1222 
       
  1223 	/**
       
  1224 	 * Filter the tags list for a given post.
       
  1225 	 *
       
  1226 	 * @since 2.3.0
       
  1227 	 *
       
  1228 	 * @param string $tag_list List of tags.
       
  1229 	 * @param string $before   String to use before tags.
       
  1230 	 * @param string $sep      String to use between the tags.
       
  1231 	 * @param string $after    String to use after tags.
       
  1232 	 * @param int    $id       Post ID.
       
  1233 	 */
  1024 	return apply_filters( 'the_tags', get_the_term_list( $id, 'post_tag', $before, $sep, $after ), $before, $sep, $after, $id );
  1234 	return apply_filters( 'the_tags', get_the_term_list( $id, 'post_tag', $before, $sep, $after ), $before, $sep, $after, $id );
  1025 }
  1235 }
  1026 
  1236 
  1027 /**
  1237 /**
  1028  * Retrieve the tags for a post.
  1238  * Retrieve the tags for a post.
  1040 }
  1250 }
  1041 
  1251 
  1042 /**
  1252 /**
  1043  * Retrieve tag description.
  1253  * Retrieve tag description.
  1044  *
  1254  *
  1045  * @since 2.8
  1255  * @since 2.8.0
  1046  *
  1256  *
  1047  * @param int $tag Optional. Tag ID. Will use global tag ID by default.
  1257  * @param int $tag Optional. Tag ID. Will use global tag ID by default.
  1048  * @return string Tag description, available.
  1258  * @return string Tag description, available.
  1049  */
  1259  */
  1050 function tag_description( $tag = 0 ) {
  1260 function tag_description( $tag = 0 ) {
  1052 }
  1262 }
  1053 
  1263 
  1054 /**
  1264 /**
  1055  * Retrieve term description.
  1265  * Retrieve term description.
  1056  *
  1266  *
  1057  * @since 2.8
  1267  * @since 2.8.0
  1058  *
  1268  *
  1059  * @param int $term Optional. Term ID. Will use global term ID by default.
  1269  * @param int $term Optional. Term ID. Will use global term ID by default.
  1060  * @param string $taxonomy Optional taxonomy name. Defaults to 'post_tag'.
  1270  * @param string $taxonomy Optional taxonomy name. Defaults to 'post_tag'.
  1061  * @return string Term description, available.
  1271  * @return string Term description, available.
  1062  */
  1272  */
  1077  *
  1287  *
  1078  * @since 2.5.0
  1288  * @since 2.5.0
  1079  *
  1289  *
  1080  * @param int|object $post Post ID or object.
  1290  * @param int|object $post Post ID or object.
  1081  * @param string $taxonomy Taxonomy name.
  1291  * @param string $taxonomy Taxonomy name.
  1082  * @return array|bool|WP_Error Array of term objects on success, false or WP_Error on failure.
  1292  * @return array|bool|WP_Error Array of term objects on success, false if there are no terms
       
  1293  *                             or the post does not exist, WP_Error on failure.
  1083  */
  1294  */
  1084 function get_the_terms( $post, $taxonomy ) {
  1295 function get_the_terms( $post, $taxonomy ) {
  1085 	if ( ! $post = get_post( $post ) )
  1296 	if ( ! $post = get_post( $post ) )
  1086 		return false;
  1297 		return false;
  1087 
  1298 
  1089 	if ( false === $terms ) {
  1300 	if ( false === $terms ) {
  1090 		$terms = wp_get_object_terms( $post->ID, $taxonomy );
  1301 		$terms = wp_get_object_terms( $post->ID, $taxonomy );
  1091 		wp_cache_add($post->ID, $terms, $taxonomy . '_relationships');
  1302 		wp_cache_add($post->ID, $terms, $taxonomy . '_relationships');
  1092 	}
  1303 	}
  1093 
  1304 
       
  1305 	/**
       
  1306 	 * Filter the list of terms attached to the given post.
       
  1307 	 *
       
  1308 	 * @since 3.1.0
       
  1309 	 *
       
  1310 	 * @param array|WP_Error $terms    List of attached terms, or WP_Error on failure.
       
  1311 	 * @param int            $post_id  Post ID.
       
  1312 	 * @param string         $taxonomy Name of the taxonomy.
       
  1313 	 */
  1094 	$terms = apply_filters( 'get_the_terms', $terms, $post->ID, $taxonomy );
  1314 	$terms = apply_filters( 'get_the_terms', $terms, $post->ID, $taxonomy );
  1095 
  1315 
  1096 	if ( empty( $terms ) )
  1316 	if ( empty( $terms ) )
  1097 		return false;
  1317 		return false;
  1098 
  1318 
  1107  * @param int $id Post ID.
  1327  * @param int $id Post ID.
  1108  * @param string $taxonomy Taxonomy name.
  1328  * @param string $taxonomy Taxonomy name.
  1109  * @param string $before Optional. Before list.
  1329  * @param string $before Optional. Before list.
  1110  * @param string $sep Optional. Separate items using this.
  1330  * @param string $sep Optional. Separate items using this.
  1111  * @param string $after Optional. After list.
  1331  * @param string $after Optional. After list.
  1112  * @return string|bool|WP_Error A list of terms on success, false or WP_Error on failure.
  1332  * @return string|bool|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure.
  1113  */
  1333  */
  1114 function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) {
  1334 function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) {
  1115 	$terms = get_the_terms( $id, $taxonomy );
  1335 	$terms = get_the_terms( $id, $taxonomy );
  1116 
  1336 
  1117 	if ( is_wp_error( $terms ) )
  1337 	if ( is_wp_error( $terms ) )
  1118 		return $terms;
  1338 		return $terms;
  1119 
  1339 
  1120 	if ( empty( $terms ) )
  1340 	if ( empty( $terms ) )
  1121 		return false;
  1341 		return false;
  1122 
  1342 
       
  1343 	$links = array();
       
  1344 
  1123 	foreach ( $terms as $term ) {
  1345 	foreach ( $terms as $term ) {
  1124 		$link = get_term_link( $term, $taxonomy );
  1346 		$link = get_term_link( $term, $taxonomy );
  1125 		if ( is_wp_error( $link ) )
  1347 		if ( is_wp_error( $link ) ) {
  1126 			return $link;
  1348 			return $link;
  1127 		$term_links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
  1349 		}
  1128 	}
  1350 		$links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
  1129 
  1351 	}
  1130 	$term_links = apply_filters( "term_links-$taxonomy", $term_links );
  1352 
       
  1353 	/**
       
  1354 	 * Filter the term links for a given taxonomy.
       
  1355 	 *
       
  1356 	 * The dynamic portion of the filter name, `$taxonomy`, refers
       
  1357 	 * to the taxonomy slug.
       
  1358 	 *
       
  1359 	 * @since 2.5.0
       
  1360 	 *
       
  1361 	 * @param array $links An array of term links.
       
  1362 	 */
       
  1363 	$term_links = apply_filters( "term_links-$taxonomy", $links );
  1131 
  1364 
  1132 	return $before . join( $sep, $term_links ) . $after;
  1365 	return $before . join( $sep, $term_links ) . $after;
  1133 }
  1366 }
  1134 
  1367 
  1135 /**
  1368 /**
  1140  * @param int $id Post ID.
  1373  * @param int $id Post ID.
  1141  * @param string $taxonomy Taxonomy name.
  1374  * @param string $taxonomy Taxonomy name.
  1142  * @param string $before Optional. Before list.
  1375  * @param string $before Optional. Before list.
  1143  * @param string $sep Optional. Separate items using this.
  1376  * @param string $sep Optional. Separate items using this.
  1144  * @param string $after Optional. After list.
  1377  * @param string $after Optional. After list.
  1145  * @return null|bool False on WordPress error. Returns null when displaying.
  1378  * @return false|null False on WordPress error. Returns null when displaying.
  1146  */
  1379  */
  1147 function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '' ) {
  1380 function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '' ) {
  1148 	$term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after );
  1381 	$term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after );
  1149 
  1382 
  1150 	if ( is_wp_error( $term_list ) )
  1383 	if ( is_wp_error( $term_list ) )
  1151 		return false;
  1384 		return false;
  1152 
  1385 
  1153 	echo apply_filters('the_terms', $term_list, $taxonomy, $before, $sep, $after);
  1386 	/**
       
  1387 	 * Filter the list of terms to display.
       
  1388 	 *
       
  1389 	 * @since 2.9.0
       
  1390 	 *
       
  1391 	 * @param array  $term_list List of terms to display.
       
  1392 	 * @param string $taxonomy  The taxonomy name.
       
  1393 	 * @param string $before    String to use before the terms.
       
  1394 	 * @param string $sep       String to use between the terms.
       
  1395 	 * @param string $after     String to use after the terms.
       
  1396 	 */
       
  1397 	echo apply_filters( 'the_terms', $term_list, $taxonomy, $before, $sep, $after );
  1154 }
  1398 }
  1155 
  1399 
  1156 /**
  1400 /**
  1157  * Check if the current post has any of given category.
  1401  * Check if the current post has any of given category.
  1158  *
  1402  *