Coding Standards: Rename $r variable used with wp_parse_args() to $parsed_args for clarity.
Props freewebmentor. Fixes #45059. Built from https://develop.svn.wordpress.org/trunk@45667 git-svn-id: http://core.svn.wordpress.org/trunk@45478 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -365,14 +365,15 @@ function wp_dropdown_categories( $args = '' ) {
|
||||
$args['taxonomy'] = 'link_category';
|
||||
}
|
||||
|
||||
$r = wp_parse_args( $args, $defaults );
|
||||
$option_none_value = $r['option_none_value'];
|
||||
// Parse incoming $args into an array and merge it with $defaults
|
||||
$parsed_args = wp_parse_args( $args, $defaults );
|
||||
$option_none_value = $args['option_none_value'];
|
||||
|
||||
if ( ! isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
|
||||
$r['pad_counts'] = true;
|
||||
if ( ! isset( $parsed_args['pad_counts'] ) && $parsed_args['show_count'] && $parsed_args['hierarchical'] ) {
|
||||
$parsed_args['pad_counts'] = true;
|
||||
}
|
||||
|
||||
$tab_index = $r['tab_index'];
|
||||
$tab_index = $parsed_args['tab_index'];
|
||||
|
||||
$tab_index_attribute = '';
|
||||
if ( (int) $tab_index > 0 ) {
|
||||
@@ -380,21 +381,21 @@ function wp_dropdown_categories( $args = '' ) {
|
||||
}
|
||||
|
||||
// Avoid clashes with the 'name' param of get_terms().
|
||||
$get_terms_args = $r;
|
||||
$get_terms_args = $parsed_args;
|
||||
unset( $get_terms_args['name'] );
|
||||
$categories = get_terms( $r['taxonomy'], $get_terms_args );
|
||||
$categories = get_terms( $parsed_args['taxonomy'], $get_terms_args );
|
||||
|
||||
$name = esc_attr( $r['name'] );
|
||||
$class = esc_attr( $r['class'] );
|
||||
$id = $r['id'] ? esc_attr( $r['id'] ) : $name;
|
||||
$required = $r['required'] ? 'required' : '';
|
||||
$name = esc_attr( $parsed_args['name'] );
|
||||
$class = esc_attr( $parsed_args['class'] );
|
||||
$id = $parsed_args['id'] ? esc_attr( $parsed_args['id'] ) : $name;
|
||||
$required = $parsed_args['required'] ? 'required' : '';
|
||||
|
||||
if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) {
|
||||
if ( ! $parsed_args['hide_if_empty'] || ! empty( $categories ) ) {
|
||||
$output = "<select $required name='$name' id='$id' class='$class' $tab_index_attribute>\n";
|
||||
} else {
|
||||
$output = '';
|
||||
}
|
||||
if ( empty( $categories ) && ! $r['hide_if_empty'] && ! empty( $r['show_option_none'] ) ) {
|
||||
if ( empty( $categories ) && ! $parsed_args['hide_if_empty'] && ! empty( $parsed_args['show_option_none'] ) ) {
|
||||
|
||||
/**
|
||||
* Filters a taxonomy drop-down display element.
|
||||
@@ -411,37 +412,37 @@ function wp_dropdown_categories( $args = '' ) {
|
||||
* @param string $element Category name.
|
||||
* @param WP_Term|null $category The category object, or null if there's no corresponding category.
|
||||
*/
|
||||
$show_option_none = apply_filters( 'list_cats', $r['show_option_none'], null );
|
||||
$show_option_none = apply_filters( 'list_cats', $parsed_args['show_option_none'], null );
|
||||
$output .= "\t<option value='" . esc_attr( $option_none_value ) . "' selected='selected'>$show_option_none</option>\n";
|
||||
}
|
||||
|
||||
if ( ! empty( $categories ) ) {
|
||||
|
||||
if ( $r['show_option_all'] ) {
|
||||
if ( $parsed_args['show_option_all'] ) {
|
||||
|
||||
/** This filter is documented in wp-includes/category-template.php */
|
||||
$show_option_all = apply_filters( 'list_cats', $r['show_option_all'], null );
|
||||
$selected = ( '0' === strval( $r['selected'] ) ) ? " selected='selected'" : '';
|
||||
$show_option_all = apply_filters( 'list_cats', $parsed_args['show_option_all'], null );
|
||||
$selected = ( '0' === strval( $parsed_args['selected'] ) ) ? " selected='selected'" : '';
|
||||
$output .= "\t<option value='0'$selected>$show_option_all</option>\n";
|
||||
}
|
||||
|
||||
if ( $r['show_option_none'] ) {
|
||||
if ( $parsed_args['show_option_none'] ) {
|
||||
|
||||
/** This filter is documented in wp-includes/category-template.php */
|
||||
$show_option_none = apply_filters( 'list_cats', $r['show_option_none'], null );
|
||||
$selected = selected( $option_none_value, $r['selected'], false );
|
||||
$show_option_none = apply_filters( 'list_cats', $parsed_args['show_option_none'], null );
|
||||
$selected = selected( $option_none_value, $parsed_args['selected'], false );
|
||||
$output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$selected>$show_option_none</option>\n";
|
||||
}
|
||||
|
||||
if ( $r['hierarchical'] ) {
|
||||
$depth = $r['depth']; // Walk the full depth.
|
||||
if ( $parsed_args['hierarchical'] ) {
|
||||
$depth = $parsed_args['depth']; // Walk the full depth.
|
||||
} else {
|
||||
$depth = -1; // Flat.
|
||||
}
|
||||
$output .= walk_category_dropdown_tree( $categories, $depth, $r );
|
||||
$output .= walk_category_dropdown_tree( $categories, $depth, $parsed_args );
|
||||
}
|
||||
|
||||
if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) {
|
||||
if ( ! $parsed_args['hide_if_empty'] || ! empty( $categories ) ) {
|
||||
$output .= "</select>\n";
|
||||
}
|
||||
/**
|
||||
@@ -450,11 +451,11 @@ function wp_dropdown_categories( $args = '' ) {
|
||||
* @since 2.1.0
|
||||
*
|
||||
* @param string $output HTML output.
|
||||
* @param array $r Arguments used to build the drop-down.
|
||||
* @param array $parsed_args Arguments used to build the drop-down.
|
||||
*/
|
||||
$output = apply_filters( 'wp_dropdown_cats', $output, $r );
|
||||
$output = apply_filters( 'wp_dropdown_cats', $output, $parsed_args );
|
||||
|
||||
if ( $r['echo'] ) {
|
||||
if ( $parsed_args['echo'] ) {
|
||||
echo $output;
|
||||
}
|
||||
return $output;
|
||||
@@ -537,48 +538,48 @@ function wp_list_categories( $args = '' ) {
|
||||
'use_desc_for_title' => 1,
|
||||
);
|
||||
|
||||
$r = wp_parse_args( $args, $defaults );
|
||||
$parsed_args = wp_parse_args( $args, $defaults );
|
||||
|
||||
if ( ! isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
|
||||
$r['pad_counts'] = true;
|
||||
if ( ! isset( $parsed_args['pad_counts'] ) && $parsed_args['show_count'] && $parsed_args['hierarchical'] ) {
|
||||
$parsed_args['pad_counts'] = true;
|
||||
}
|
||||
|
||||
// Descendants of exclusions should be excluded too.
|
||||
if ( true == $r['hierarchical'] ) {
|
||||
if ( true == $parsed_args['hierarchical'] ) {
|
||||
$exclude_tree = array();
|
||||
|
||||
if ( $r['exclude_tree'] ) {
|
||||
$exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $r['exclude_tree'] ) );
|
||||
if ( $parsed_args['exclude_tree'] ) {
|
||||
$exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $parsed_args['exclude_tree'] ) );
|
||||
}
|
||||
|
||||
if ( $r['exclude'] ) {
|
||||
$exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $r['exclude'] ) );
|
||||
if ( $parsed_args['exclude'] ) {
|
||||
$exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $parsed_args['exclude'] ) );
|
||||
}
|
||||
|
||||
$r['exclude_tree'] = $exclude_tree;
|
||||
$r['exclude'] = '';
|
||||
$parsed_args['exclude_tree'] = $exclude_tree;
|
||||
$parsed_args['exclude'] = '';
|
||||
}
|
||||
|
||||
if ( ! isset( $r['class'] ) ) {
|
||||
$r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];
|
||||
if ( ! isset( $parsed_args['class'] ) ) {
|
||||
$parsed_args['class'] = ( 'category' == $parsed_args['taxonomy'] ) ? 'categories' : $parsed_args['taxonomy'];
|
||||
}
|
||||
|
||||
if ( ! taxonomy_exists( $r['taxonomy'] ) ) {
|
||||
if ( ! taxonomy_exists( $parsed_args['taxonomy'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$show_option_all = $r['show_option_all'];
|
||||
$show_option_none = $r['show_option_none'];
|
||||
$show_option_all = $parsed_args['show_option_all'];
|
||||
$show_option_none = $parsed_args['show_option_none'];
|
||||
|
||||
$categories = get_categories( $r );
|
||||
$categories = get_categories( $parsed_args );
|
||||
|
||||
$output = '';
|
||||
if ( $r['title_li'] && 'list' == $r['style'] && ( ! empty( $categories ) || ! $r['hide_title_if_empty'] ) ) {
|
||||
$output = '<li class="' . esc_attr( $r['class'] ) . '">' . $r['title_li'] . '<ul>';
|
||||
if ( $parsed_args['title_li'] && 'list' == $parsed_args['style'] && ( ! empty( $categories ) || ! $parsed_args['hide_title_if_empty'] ) ) {
|
||||
$output = '<li class="' . esc_attr( $parsed_args['class'] ) . '">' . $parsed_args['title_li'] . '<ul>';
|
||||
}
|
||||
if ( empty( $categories ) ) {
|
||||
if ( ! empty( $show_option_none ) ) {
|
||||
if ( 'list' == $r['style'] ) {
|
||||
if ( 'list' == $parsed_args['style'] ) {
|
||||
$output .= '<li class="cat-item-none">' . $show_option_none . '</li>';
|
||||
} else {
|
||||
$output .= $show_option_none;
|
||||
@@ -590,7 +591,7 @@ function wp_list_categories( $args = '' ) {
|
||||
$posts_page = '';
|
||||
|
||||
// For taxonomies that belong only to custom post types, point to a valid archive.
|
||||
$taxonomy_object = get_taxonomy( $r['taxonomy'] );
|
||||
$taxonomy_object = get_taxonomy( $parsed_args['taxonomy'] );
|
||||
if ( ! in_array( 'post', $taxonomy_object->object_type ) && ! in_array( 'page', $taxonomy_object->object_type ) ) {
|
||||
foreach ( $taxonomy_object->object_type as $object_type ) {
|
||||
$_object_type = get_post_type_object( $object_type );
|
||||
@@ -613,29 +614,29 @@ function wp_list_categories( $args = '' ) {
|
||||
}
|
||||
|
||||
$posts_page = esc_url( $posts_page );
|
||||
if ( 'list' == $r['style'] ) {
|
||||
if ( 'list' == $parsed_args['style'] ) {
|
||||
$output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>";
|
||||
} else {
|
||||
$output .= "<a href='$posts_page'>$show_option_all</a>";
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) {
|
||||
if ( empty( $parsed_args['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) {
|
||||
$current_term_object = get_queried_object();
|
||||
if ( $current_term_object && $r['taxonomy'] === $current_term_object->taxonomy ) {
|
||||
$r['current_category'] = get_queried_object_id();
|
||||
if ( $current_term_object && $parsed_args['taxonomy'] === $current_term_object->taxonomy ) {
|
||||
$parsed_args['current_category'] = get_queried_object_id();
|
||||
}
|
||||
}
|
||||
|
||||
if ( $r['hierarchical'] ) {
|
||||
$depth = $r['depth'];
|
||||
if ( $parsed_args['hierarchical'] ) {
|
||||
$depth = $parsed_args['depth'];
|
||||
} else {
|
||||
$depth = -1; // Flat.
|
||||
}
|
||||
$output .= walk_category_tree( $categories, $depth, $r );
|
||||
$output .= walk_category_tree( $categories, $depth, $parsed_args );
|
||||
}
|
||||
|
||||
if ( $r['title_li'] && 'list' == $r['style'] && ( ! empty( $categories ) || ! $r['hide_title_if_empty'] ) ) {
|
||||
if ( $parsed_args['title_li'] && 'list' == $parsed_args['style'] && ( ! empty( $categories ) || ! $parsed_args['hide_title_if_empty'] ) ) {
|
||||
$output .= '</ul></li>';
|
||||
}
|
||||
|
||||
@@ -649,7 +650,7 @@ function wp_list_categories( $args = '' ) {
|
||||
*/
|
||||
$html = apply_filters( 'wp_list_categories', $output, $args );
|
||||
|
||||
if ( $r['echo'] ) {
|
||||
if ( $parsed_args['echo'] ) {
|
||||
echo $html;
|
||||
} else {
|
||||
return $html;
|
||||
|
||||
Reference in New Issue
Block a user