From 1b63ada83d68d1a09ff6a56d9002c53b18942fb3 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 2 Jan 2015 21:34:23 +0000 Subject: [PATCH] Introduce 'name' parameter for `get_terms()`. This enhancement requires a modification in the way that `wp_dropdown_categories()` prepares its arguments for `get_terms()`, so that its unrelated 'name' param is not mistaken for the new 'name' argument in `get_terms()`. Props danielbachhuber. Fixes #30611. Built from https://develop.svn.wordpress.org/trunk@31024 git-svn-id: http://core.svn.wordpress.org/trunk@31005 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/category-template.php | 7 ++++++- wp-includes/taxonomy.php | 14 +++++++++++++- wp-includes/version.php | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index f8c6a56aa1..7f2c539676 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -376,7 +376,12 @@ function wp_dropdown_categories( $args = '' ) { if ( (int) $tab_index > 0 ) { $tab_index_attribute = " tabindex=\"$tab_index\""; } - $categories = get_terms( $r['taxonomy'], $r ); + + // Avoid clashes with the 'name' param of get_terms(). + $get_terms_args = $r; + unset( $get_terms_args['name'] ); + $categories = get_terms( $r['taxonomy'], $get_terms_args ); + $name = esc_attr( $r['name'] ); $class = esc_attr( $r['class'] ); $id = $r['id'] ? esc_attr( $r['id'] ) : $name; diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 63d53a7762..1e3e2a6565 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1548,6 +1548,7 @@ function get_term_to_edit( $id, $taxonomy ) { * along with the $args array. * * @since 2.3.0 + * @since 4.2.0 Introduced 'name' parameter. * * @global wpdb $wpdb WordPress database abstraction object. * @@ -1578,6 +1579,7 @@ function get_term_to_edit( $id, $taxonomy ) { * @type string $fields Term fields to query for. Accepts 'all' (returns an array of * term objects), 'ids' or 'names' (returns an array of integers * or strings, respectively. Default 'all'. + * @type string|array $name Optional. Name or array of names to return term(s) for. Default empty. * @type string|array $slug Optional. Slug or array of slugs to return term(s) for. Default empty. * @type bool $hierarchical Whether to include terms that have non-empty descendants (even * if $hide_empty is set to true). Default true. @@ -1618,7 +1620,7 @@ function get_terms( $taxonomies, $args = '' ) { $defaults = array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), - 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', + 'number' => '', 'fields' => 'all', 'name' => '', 'slug' => '', 'parent' => '', 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'description__like' => '', 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' ); $args = wp_parse_args( $args, $defaults ); @@ -1795,6 +1797,16 @@ function get_terms( $taxonomies, $args = '' ) { $where .= $exclusions; } + if ( ! empty( $args['name'] ) ) { + if ( is_array( $args['name'] ) ) { + $name = array_map( 'sanitize_text_field', $args['name'] ); + $where .= " AND t.name IN ('" . implode( "', '", $name ) . "')"; + } else { + $name = sanitize_text_field( $args['name'] ); + $where .= $wpdb->prepare( " AND t.name = %s", $name ); + } + } + if ( ! empty( $args['slug'] ) ) { if ( is_array( $args['slug'] ) ) { $slug = array_map( 'sanitize_title', $args['slug'] ); diff --git a/wp-includes/version.php b/wp-includes/version.php index cd16c6cde6..937b4b977e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31023'; +$wp_version = '4.2-alpha-31024'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.