mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-07 08:01:54 +01:00
Taxonomy: Allow for wp_count_terms( $args )
signature, making passing a taxonomy optional.
This brings `wp_count_terms()` in line with other taxonomy functions such as `get_terms()` which technically no longer require a taxonomy. Similar to the previously modified functions, no deprecation warning is triggered when using the legacy signature. Fixes #36399. Built from https://develop.svn.wordpress.org/trunk@48840 git-svn-id: http://core.svn.wordpress.org/trunk@48602 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
40ea11468b
commit
5918f7e11d
@ -129,7 +129,12 @@ class WP_Terms_List_Table extends WP_List_Table {
|
||||
|
||||
$this->set_pagination_args(
|
||||
array(
|
||||
'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ),
|
||||
'total_items' => wp_count_terms(
|
||||
array(
|
||||
'taxonomy' => $this->screen->taxonomy,
|
||||
'search' => $search,
|
||||
)
|
||||
),
|
||||
'per_page' => $tags_per_page,
|
||||
)
|
||||
);
|
||||
|
@ -725,7 +725,6 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) {
|
||||
|
||||
$num_pages = ceil(
|
||||
wp_count_terms(
|
||||
$taxonomy_name,
|
||||
array_merge(
|
||||
$args,
|
||||
array(
|
||||
|
@ -263,7 +263,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
||||
|
||||
unset( $count_args['number'], $count_args['offset'] );
|
||||
|
||||
$total_terms = wp_count_terms( $this->taxonomy, $count_args );
|
||||
$total_terms = wp_count_terms( $count_args );
|
||||
|
||||
// wp_count_terms() can return a falsey value when the term has no children.
|
||||
if ( ! $total_terms ) {
|
||||
|
@ -150,7 +150,7 @@ class WP_Sitemaps_Taxonomies extends WP_Sitemaps_Provider {
|
||||
return $max_num_pages;
|
||||
}
|
||||
|
||||
$term_count = wp_count_terms( $taxonomy, $this->get_taxonomies_query_args( $taxonomy ) );
|
||||
$term_count = wp_count_terms( $this->get_taxonomies_query_args( $taxonomy ) );
|
||||
|
||||
return (int) ceil( $term_count / wp_sitemaps_get_max_urls( $this->object_type ) );
|
||||
}
|
||||
|
@ -1730,18 +1730,24 @@ function sanitize_term_field( $field, $value, $term_id, $taxonomy, $context ) {
|
||||
* Default $args is 'hide_empty' which can be 'hide_empty=true' or array('hide_empty' => true).
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 5.6.0 Changed the function signature so that the `$args` array can be provided as the first parameter.
|
||||
*
|
||||
* @param string $taxonomy Taxonomy name.
|
||||
* @param array|string $args Optional. Array of arguments that get passed to get_terms().
|
||||
* Default empty array.
|
||||
* @param array|string $args Optional. Array of arguments that get passed to get_terms().
|
||||
* Default empty array.
|
||||
* @param array|string $deprecated Taxonomy name.
|
||||
* @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(
|
||||
'taxonomy' => $taxonomy,
|
||||
'hide_empty' => false,
|
||||
);
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
function wp_count_terms( $args = array(), $deprecated = array() ) {
|
||||
// Check whether function is used with legacy signature `$taxonomy` and `$args`.
|
||||
$use_legacy_args = $args && ( is_string( $args ) && taxonomy_exists( $args ) || is_array( $args ) && wp_is_numeric_array( $args ) );
|
||||
|
||||
$defaults = array( 'hide_empty' => false );
|
||||
if ( $use_legacy_args ) {
|
||||
$defaults['taxonomy'] = $args;
|
||||
$args = $deprecated;
|
||||
}
|
||||
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
|
||||
// Backward compatibility.
|
||||
if ( isset( $args['ignore_empty'] ) ) {
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.6-alpha-48839';
|
||||
$wp_version = '5.6-alpha-48840';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user