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
This commit is contained in:
Boone Gorges 2015-01-02 21:34:23 +00:00
parent e0189c3686
commit 1b63ada83d
3 changed files with 20 additions and 3 deletions

View File

@ -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;

View File

@ -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'] );

View File

@ -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.