Taxonomy: Fix deprecated calls to `get_terms()`.

The taxonomy should be passed as part of `$args`, rather than as its own argument.

Props sgastard, mukesh27, SergeyBiryukov.
Fixes #47819.
Built from https://develop.svn.wordpress.org/trunk@45723


git-svn-id: http://core.svn.wordpress.org/trunk@45534 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-08-03 03:35:56 +00:00
parent 60431f3c53
commit c26f1c5d90
19 changed files with 73 additions and 49 deletions

View File

@ -151,8 +151,8 @@ function wp_ajax_ajax_tag_search() {
}
$results = get_terms(
$taxonomy,
array(
'taxonomy' => $taxonomy,
'name__like' => $s,
'fields' => 'names',
'hide_empty' => false,
@ -1085,11 +1085,11 @@ function wp_ajax_get_tagcloud() {
}
$tags = get_terms(
$taxonomy,
array(
'number' => 45,
'orderby' => 'count',
'order' => 'DESC',
'taxonomy' => $taxonomy,
'number' => 45,
'orderby' => 'count',
'order' => 'DESC',
)
);

View File

@ -214,6 +214,7 @@ class WP_Terms_List_Table extends WP_List_Table {
$args = wp_parse_args(
$this->callback_args,
array(
'taxonomy' => $taxonomy,
'page' => 1,
'number' => 20,
'search' => '',
@ -237,7 +238,8 @@ class WP_Terms_List_Table extends WP_List_Table {
$args['number'] = 0;
$args['offset'] = $args['number'];
}
$terms = get_terms( $taxonomy, $args );
$terms = get_terms( $args );
if ( empty( $terms ) || ! is_array( $terms ) ) {
echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';

View File

@ -159,7 +159,12 @@ function export_wp( $args = array() ) {
$tags = (array) get_tags( array( 'get' => 'all' ) );
$custom_taxonomies = get_taxonomies( array( '_builtin' => false ) );
$custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) );
$custom_terms = (array) get_terms(
array(
'taxonomy' => $custom_taxonomies,
'get' => 'all',
)
);
// Put categories in order with no child going before its parent.
while ( $cat = array_shift( $categories ) ) {

View File

@ -663,6 +663,7 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) {
$offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
$args = array(
'taxonomy' => $taxonomy_name,
'child_of' => 0,
'exclude' => '',
'hide_empty' => false,
@ -675,7 +676,7 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) {
'pad_counts' => false,
);
$terms = get_terms( $taxonomy_name, $args );
$terms = get_terms( $args );
if ( ! $terms || is_wp_error( $terms ) ) {
echo '<p>' . __( 'No items.' ) . '</p>';
@ -774,8 +775,8 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) {
<ul id="<?php echo $taxonomy_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
<?php
$popular_terms = get_terms(
$taxonomy_name,
array(
'taxonomy' => $taxonomy_name,
'orderby' => 'count',
'order' => 'DESC',
'number' => 10,
@ -812,8 +813,8 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) {
if ( isset( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) {
$searched = esc_attr( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] );
$search_results = get_terms(
$taxonomy_name,
array(
'taxonomy' => $taxonomy_name,
'name__like' => $searched,
'fields' => 'all',
'orderby' => 'count',

View File

@ -2041,8 +2041,8 @@ function taxonomy_meta_box_sanitize_cb_input( $taxonomy, $terms ) {
}
$_term = get_terms(
$taxonomy,
array(
'taxonomy' => $taxonomy,
'name' => $term,
'fields' => 'ids',
'hide_empty' => false,

View File

@ -125,12 +125,13 @@ function wp_terms_checklist( $post_id = 0, $args = array() ) {
} else {
$args['selected_cats'] = array();
}
if ( is_array( $parsed_args['popular_cats'] ) ) {
$args['popular_cats'] = $parsed_args['popular_cats'];
} else {
$args['popular_cats'] = get_terms(
$taxonomy,
array(
'taxonomy' => $taxonomy,
'fields' => 'ids',
'orderby' => 'count',
'order' => 'DESC',
@ -139,10 +140,11 @@ function wp_terms_checklist( $post_id = 0, $args = array() ) {
)
);
}
if ( $descendants_and_self ) {
$categories = (array) get_terms(
$taxonomy,
array(
'taxonomy' => $taxonomy,
'child_of' => $descendants_and_self,
'hierarchical' => 0,
'hide_empty' => 0,
@ -151,7 +153,12 @@ function wp_terms_checklist( $post_id = 0, $args = array() ) {
$self = get_term( $descendants_and_self, $taxonomy );
array_unshift( $categories, $self );
} else {
$categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) );
$categories = (array) get_terms(
array(
'taxonomy' => $taxonomy,
'get' => 'all',
)
);
}
$output = '';
@ -207,8 +214,8 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ech
}
$terms = get_terms(
$taxonomy,
array(
'taxonomy' => $taxonomy,
'orderby' => 'count',
'order' => 'DESC',
'number' => $number,
@ -266,8 +273,8 @@ function wp_link_category_checklist( $link_id = 0 ) {
}
$categories = get_terms(
'link_category',
array(
'taxonomy' => 'link_category',
'orderby' => 'name',
'hide_empty' => 0,
)

View File

@ -237,8 +237,8 @@ function wp_list_bookmarks( $args = '' ) {
if ( $parsed_args['categorize'] ) {
$cats = get_terms(
'link_category',
array(
'taxonomy' => 'link_category',
'name__like' => $parsed_args['category_name'],
'include' => $parsed_args['category'],
'exclude' => $parsed_args['exclude_category'],

View File

@ -384,7 +384,7 @@ function wp_dropdown_categories( $args = '' ) {
// Avoid clashes with the 'name' param of get_terms().
$get_terms_args = $parsed_args;
unset( $get_terms_args['name'] );
$categories = get_terms( $parsed_args['taxonomy'], $get_terms_args );
$categories = get_terms( $get_terms_args );
$name = esc_attr( $parsed_args['name'] );
$class = esc_attr( $parsed_args['class'] );
@ -701,7 +701,6 @@ function wp_tag_cloud( $args = '' ) {
$args = wp_parse_args( $args, $defaults );
$tags = get_terms(
$args['taxonomy'],
array_merge(
$args,
array(

View File

@ -27,8 +27,6 @@ function get_categories( $args = '' ) {
$defaults = array( 'taxonomy' => 'category' );
$args = wp_parse_args( $args, $defaults );
$taxonomy = $args['taxonomy'];
/**
* Filters the taxonomy used to retrieve terms when calling get_categories().
*
@ -37,7 +35,7 @@ function get_categories( $args = '' ) {
* @param string $taxonomy Taxonomy to retrieve terms from.
* @param array $args An array of arguments. See get_terms().
*/
$taxonomy = apply_filters( 'get_categories_taxonomy', $taxonomy, $args );
$args['taxonomy'] = apply_filters( 'get_categories_taxonomy', $args['taxonomy'], $args );
// Back compat
if ( isset( $args['type'] ) && 'link' == $args['type'] ) {
@ -51,11 +49,10 @@ function get_categories( $args = '' ) {
'<code>taxonomy => link_category</code>'
)
);
$taxonomy = 'link_category';
$args['taxonomy'] = $taxonomy;
$args['taxonomy'] = 'link_category';
}
$categories = get_terms( $taxonomy, $args );
$categories = get_terms( $args );
if ( is_wp_error( $categories ) ) {
$categories = array();
@ -136,10 +133,10 @@ function get_category_by_path( $category_path, $full_match = true, $output = OBJ
$full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title( $pathdir );
}
$categories = get_terms(
'category',
array(
'get' => 'all',
'slug' => $leaf_path,
'taxonomy' => 'category',
'get' => 'all',
'slug' => $leaf_path,
)
);
@ -279,7 +276,10 @@ function sanitize_category_field( $field, $value, $cat_id, $context ) {
* @return WP_Term[]|int $tags Array of 'post_tag' term objects, or a count thereof.
*/
function get_tags( $args = '' ) {
$tags = get_terms( 'post_tag', $args );
$defaults = array( 'taxonomy' => 'post_tag' );
$args = wp_parse_args( $args, $defaults );
$tags = get_terms( $args );
if ( empty( $tags ) ) {
$return = array();

View File

@ -200,8 +200,8 @@ class Walker_Category extends Walker {
if ( ! empty( $args['current_category'] ) ) {
// 'current_category' can be an array, so we use `get_terms()`.
$_current_terms = get_terms(
$category->taxonomy,
array(
'taxonomy' => $category->taxonomy,
'include' => $args['current_category'],
'hide_empty' => false,
)

View File

@ -210,8 +210,8 @@ final class WP_Customize_Nav_Menus {
}
} elseif ( 'taxonomy' === $type ) {
$terms = get_terms(
$object,
array(
'taxonomy' => $object,
'child_of' => 0,
'exclude' => '',
'hide_empty' => false,
@ -365,8 +365,8 @@ final class WP_Customize_Nav_Menus {
// Query taxonomy terms.
$taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'names' );
$terms = get_terms(
$taxonomies,
array(
'taxonomies' => $taxonomies,
'name__like' => $args['s'],
'number' => 20,
'offset' => 20 * ( $args['pagenum'] - 1 ),

View File

@ -428,8 +428,8 @@ class WP_Term_Query {
$excluded_children = array_merge(
$excluded_children,
(array) get_terms(
reset( $taxonomies ),
array(
'taxonomy' => reset( $taxonomies ),
'child_of' => intval( $extrunk ),
'fields' => 'ids',
'hide_empty' => 0,

View File

@ -1557,8 +1557,8 @@ class wp_xmlrpc_server extends IXR_Server {
$ambiguous_terms = array();
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
$tax_term_names = get_terms(
$taxonomy,
array(
'taxonomy' => $taxonomy,
'fields' => 'names',
'hide_empty' => false,
)
@ -2390,7 +2390,7 @@ class wp_xmlrpc_server extends IXR_Server {
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) );
}
$query = array();
$query = array( 'taxonomy' => $taxonomy->name );
if ( isset( $filter['number'] ) ) {
$query['number'] = absint( $filter['number'] );
@ -2418,7 +2418,7 @@ class wp_xmlrpc_server extends IXR_Server {
$query['search'] = $filter['search'];
}
$terms = get_terms( $taxonomy->name, $query );
$terms = get_terms( $query );
if ( is_wp_error( $terms ) ) {
return new IXR_Error( 500, $terms->get_error_message() );

View File

@ -1287,7 +1287,13 @@ function get_all_category_ids() {
_deprecated_function( __FUNCTION__, '4.0.0', 'get_terms()' );
if ( ! $cat_ids = wp_cache_get( 'all_category_ids', 'category' ) ) {
$cat_ids = get_terms( 'category', array('fields' => 'ids', 'get' => 'all') );
$cat_ids = get_terms(
array(
'taxonomy' => 'category',
'fields' => 'ids',
'get' => 'all',
)
);
wp_cache_add( 'all_category_ids', $cat_ids, 'category' );
}

View File

@ -597,6 +597,7 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item
*/
function wp_get_nav_menus( $args = array() ) {
$defaults = array(
'taxonomy' => 'nav_menu',
'hide_empty' => false,
'orderby' => 'name',
);
@ -612,7 +613,7 @@ function wp_get_nav_menus( $args = array() ) {
* @param array $menus An array of menu objects.
* @param array $args An array of arguments used to retrieve menu objects.
*/
return apply_filters( 'wp_get_nav_menus', get_terms( 'nav_menu', $args ), $args );
return apply_filters( 'wp_get_nav_menus', get_terms( $args ), $args );
}
/**
@ -727,8 +728,8 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
if ( ! empty( $terms ) ) {
foreach ( array_keys( $terms ) as $taxonomy ) {
get_terms(
$taxonomy,
array(
'taxonomy' => $taxonomy,
'include' => $terms[ $taxonomy ],
'hierarchical' => false,
)

View File

@ -184,7 +184,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
'slug' => 'slug',
);
$prepared_args = array();
$prepared_args = array( 'taxonomy' => $this->taxonomy );
/*
* For each known parameter which is both registered and present in the request,
@ -249,7 +249,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
// Used when calling wp_count_terms() below.
$prepared_args['object_ids'] = $prepared_args['post'];
} else {
$query_result = get_terms( $this->taxonomy, $prepared_args );
$query_result = get_terms( $prepared_args );
}
$count_args = $prepared_args;

View File

@ -1131,7 +1131,7 @@ function get_term_to_edit( $id, $taxonomy ) {
* @param array $deprecated Argument array, when using the legacy function parameter format. If present, this
* parameter will be interpreted as `$args`, and the first function parameter will
* be parsed as a taxonomy or array of taxonomies.
* @return array|int|WP_Error List of WP_Term instances and their children. Will return WP_Error, if any of $taxonomies
* @return array|int|WP_Error List of WP_Term instances and their children. Will return WP_Error, if any of taxonomies
* do not exist.
*/
function get_terms( $args = array(), $deprecated = '' ) {
@ -1685,7 +1685,10 @@ function sanitize_term_field( $field, $value, $term_id, $taxonomy, $context ) {
* @return array|int|WP_Error Number of terms in that taxonomy or WP_Error if the taxonomy does not exist.
*/
function wp_count_terms( $taxonomy, $args = array() ) {
$defaults = array( 'hide_empty' => false );
$defaults = array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
);
$args = wp_parse_args( $args, $defaults );
// backward compatibility
@ -1696,7 +1699,7 @@ function wp_count_terms( $taxonomy, $args = array() ) {
$args['fields'] = 'count';
return get_terms( $taxonomy, $args );
return get_terms( $args );
}
/**
@ -2191,8 +2194,8 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
* unless a unique slug has been explicitly provided.
*/
$name_matches = get_terms(
$taxonomy,
array(
'taxonomy' => $taxonomy,
'name' => $name,
'hide_empty' => false,
'parent' => $args['parent'],
@ -2219,8 +2222,8 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
if ( ! $slug_provided || $name_match->slug === $slug || $slug_match ) {
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
$siblings = get_terms(
$taxonomy,
array(
'taxonomy' => $taxonomy,
'get' => 'all',
'parent' => $parent,
'update_term_meta_cache' => false,
@ -3470,8 +3473,8 @@ function _get_term_hierarchy( $taxonomy ) {
}
$children = array();
$terms = get_terms(
$taxonomy,
array(
'taxonomy' => $taxonomy,
'get' => 'all',
'orderby' => 'id',
'fields' => 'id=>parent',

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-alpha-45722';
$wp_version = '5.3-alpha-45723';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -137,7 +137,7 @@ class WP_Widget_Links extends WP_Widget {
'limit' => -1,
)
);
$link_cats = get_terms( 'link_category' );
$link_cats = get_terms( array( 'taxonomy' => 'link_category' ) );
$limit = intval( $instance['limit'] );
if ( ! $limit ) {
$limit = -1;