X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/699231ae09f7057a4d0000cdf32e50a3df6a04ca..bf5c68485ef07868ad0a91168ecd0092af7661ae:/wp-includes/category-template.php diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index db55a12c..2be9eed7 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -10,32 +10,21 @@ * Retrieve category link URL. * * @since 1.0.0 - * @uses apply_filters() Calls 'category_link' filter on category link and category ID. + * @see get_term_link() * - * @param int $category_id Category ID. - * @return string + * @param int|object $category Category ID or object. + * @return string Link on success, empty string if category does not exist. */ -function get_category_link( $category_id ) { - global $wp_rewrite; - $catlink = $wp_rewrite->get_category_permastruct(); +function get_category_link( $category ) { + if ( ! is_object( $category ) ) + $category = (int) $category; - if ( empty( $catlink ) ) { - $catlink = home_url('?cat=' . $category_id); - } else { - $category = &get_category( $category_id ); - if ( is_wp_error( $category ) ) - return $category; - $category_nicename = $category->slug; - - if ( $category->parent == $category_id ) // recursive recursion - $category->parent = 0; - elseif ($category->parent != 0 ) - $category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename; - - $catlink = str_replace( '%category%', $category_nicename, $catlink ); - $catlink = home_url( user_trailingslashit( $catlink, 'category' ) ); - } - return apply_filters( 'category_link', $catlink, $category_id ); + $category = get_term_link( $category, 'category' ); + + if ( is_wp_error( $category ) ) + return ''; + + return $category; } /** @@ -59,7 +48,7 @@ function get_category_parents( $id, $link = false, $separator = '/', $nicename = if ( $nicename ) $name = $parent->slug; else - $name = $parent->cat_name; + $name = $parent->name; if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) { $visited[] = $parent->parent; @@ -67,7 +56,7 @@ function get_category_parents( $id, $link = false, $separator = '/', $nicename = } if ( $link ) - $chain .= 'cat_name ) ) . '">'.$name.'' . $separator; + $chain .= 'name ) ) . '">'.$name.'' . $separator; else $chain .= $name.$separator; return $chain; @@ -83,28 +72,18 @@ function get_category_parents( $id, $link = false, $separator = '/', $nicename = * @return array */ function get_the_category( $id = false ) { - global $post; - - $id = (int) $id; - if ( !$id ) - $id = (int) $post->ID; - - $categories = get_object_term_cache( $id, 'category' ); - if ( false === $categories ) { - $categories = wp_get_object_terms( $id, 'category' ); - wp_cache_add($id, $categories, 'category_relationships'); - } - - if ( !empty( $categories ) ) - usort( $categories, '_usort_terms_by_name' ); - else + $categories = get_the_terms( $id, 'category' ); + if ( ! $categories ) $categories = array(); - foreach ( (array) array_keys( $categories ) as $key ) { + $categories = array_values( $categories ); + + foreach ( array_keys( $categories ) as $key ) { _make_cat_compat( $categories[$key] ); } - return $categories; + // Filter name is plural because we return alot of categories (possibly more than #13237) not just one + return apply_filters( 'get_the_categories', $categories ); } /** @@ -202,7 +181,7 @@ function get_the_category_list( $separator = '', $parents='', $post_id = false ) break; case '': default: - $thelist .= 'name ) ) . '" ' . $rel . '>' . $category->cat_name.''; + $thelist .= 'name ) ) . '" ' . $rel . '>' . $category->name.''; } } $thelist .= ''; @@ -215,13 +194,13 @@ function get_the_category_list( $separator = '', $parents='', $post_id = false ) case 'multiple': if ( $category->parent ) $thelist .= get_category_parents( $category->parent, true, $separator ); - $thelist .= 'name ) ) . '" ' . $rel . '>' . $category->cat_name.''; + $thelist .= 'name ) ) . '" ' . $rel . '>' . $category->name.''; break; case 'single': $thelist .= 'name ) ) . '" ' . $rel . '>'; if ( $category->parent ) $thelist .= get_category_parents( $category->parent, false, $separator ); - $thelist .= "$category->cat_name"; + $thelist .= "$category->name"; break; case '': default: @@ -248,29 +227,15 @@ function get_the_category_list( $separator = '', $parents='', $post_id = false ) * * @since 1.2.0 * - * @uses is_object_in_term() - * - * @param int|string|array $category. Category ID, name or slug, or array of said. - * @param int|post object Optional. Post to check instead of the current post. @since 2.7.0 + * @param int|string|array $category Category ID, name or slug, or array of said. + * @param int|object $_post Optional. Post to check instead of the current post. (since 2.7.0) * @return bool True if the current post is in any of the given categories. */ -function in_category( $category, $_post = null ) { +function in_category( $category, $post = null ) { if ( empty( $category ) ) return false; - if ( $_post ) { - $_post = get_post( $_post ); - } else { - $_post =& $GLOBALS['post']; - } - - if ( !$_post ) - return false; - - $r = is_object_in_term( $_post->ID, 'category', $category ); - if ( is_wp_error( $r ) ) - return false; - return $r; + return has_term( $category, 'category', $post ); } /** @@ -489,7 +454,7 @@ function wp_list_categories( $args = '' ) { $output = ''; if ( $title_li && 'list' == $style ) - $output = '
  • ' . $title_li . '