Eliminate use of `extract()` in `wp_list_categories()`.

See #22400.


git-svn-id: https://develop.svn.wordpress.org/trunk@28434 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-05-15 17:27:18 +00:00
parent 812493f259
commit 7793a90fd1
1 changed files with 27 additions and 21 deletions

View File

@ -485,52 +485,57 @@ function wp_list_categories( $args = '' ) {
$r['exclude'] = ''; $r['exclude'] = '';
} }
if ( !isset( $r['class'] ) ) if ( ! isset( $r['class'] ) )
$r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy']; $r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];
extract( $r ); if ( ! taxonomy_exists( $r['taxonomy'] ) ) {
if ( !taxonomy_exists($taxonomy) )
return false; return false;
}
$show_option_all = $r['show_option_all'];
$show_option_none = $r['show_option_none'];
$categories = get_categories( $r ); $categories = get_categories( $r );
$output = ''; $output = '';
if ( $title_li && 'list' == $style ) if ( $r['title_li'] && 'list' == $r['style'] ) {
$output = '<li class="' . esc_attr( $class ) . '">' . $title_li . '<ul>'; $output = '<li class="' . esc_attr( $r['class'] ) . '">' . $r['title_li'] . '<ul>';
}
if ( empty( $categories ) ) { if ( empty( $categories ) ) {
if ( ! empty( $show_option_none ) ) { if ( ! empty( $show_option_none ) ) {
if ( 'list' == $style ) if ( 'list' == $r['style'] ) {
$output .= '<li class="cat-item-none">' . $show_option_none . '</li>'; $output .= '<li class="cat-item-none">' . $show_option_none . '</li>';
else } else {
$output .= $show_option_none; $output .= $show_option_none;
}
} }
} else { } else {
if ( ! empty( $show_option_all ) ) { if ( ! empty( $show_option_all ) ) {
$posts_page = ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' ); $posts_page = ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' );
$posts_page = esc_url( $posts_page ); $posts_page = esc_url( $posts_page );
if ( 'list' == $style ) if ( 'list' == $r['style'] ) {
$output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>"; $output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>";
else } else {
$output .= "<a href='$posts_page'>$show_option_all</a>"; $output .= "<a href='$posts_page'>$show_option_all</a>";
}
} }
if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) { if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) {
$current_term_object = get_queried_object(); $current_term_object = get_queried_object();
if ( $current_term_object && $r['taxonomy'] === $current_term_object->taxonomy ) if ( $current_term_object && $r['taxonomy'] === $current_term_object->taxonomy ) {
$r['current_category'] = get_queried_object_id(); $r['current_category'] = get_queried_object_id();
}
} }
if ( $hierarchical ) if ( $r['hierarchical'] ) {
$depth = $r['depth']; $depth = $r['depth'];
else } else {
$depth = -1; // Flat. $depth = -1; // Flat.
}
$output .= walk_category_tree( $categories, $depth, $r ); $output .= walk_category_tree( $categories, $depth, $r );
} }
if ( $title_li && 'list' == $style ) if ( $r['title_li'] && 'list' == $r['style'] )
$output .= '</ul></li>'; $output .= '</ul></li>';
/** /**
@ -541,12 +546,13 @@ function wp_list_categories( $args = '' ) {
* @param string $output HTML output. * @param string $output HTML output.
* @param array $args An array of taxonomy-listing arguments. * @param array $args An array of taxonomy-listing arguments.
*/ */
$output = apply_filters( 'wp_list_categories', $output, $args ); $html = apply_filters( 'wp_list_categories', $output, $args );
if ( $echo ) if ( $r['echo'] ) {
echo $output; echo $html;
else } else {
return $output; return $html;
}
} }
/** /**