WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/21/2020 10:30:06 PM (2 months ago)
Author:
flixos90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r48782 r48840  
    17311731 *
    17321732 * @since 2.3.0
    1733  *
    1734  * @param string       $taxonomy Taxonomy name.
    1735  * @param array|string $args     Optional. Array of arguments that get passed to get_terms().
    1736  *                               Default empty array.
     1733 * @since 5.6.0 Changed the function signature so that the `$args` array can be provided as the first parameter.
     1734 *
     1735 * @param array|string $args       Optional. Array of arguments that get passed to get_terms().
     1736 *                                 Default empty array.
     1737 * @param array|string $deprecated Taxonomy name.
    17371738 * @return array|int|WP_Error Number of terms in that taxonomy or WP_Error if the taxonomy does not exist.
    17381739 */
    1739 function wp_count_terms( $taxonomy, $args = array() ) {
    1740     $defaults = array(
    1741         'taxonomy'   => $taxonomy,
    1742         'hide_empty' => false,
    1743     );
    1744     $args     = wp_parse_args( $args, $defaults );
     1740function wp_count_terms( $args = array(), $deprecated = array() ) {
     1741    // Check whether function is used with legacy signature `$taxonomy` and `$args`.
     1742    $use_legacy_args = $args && ( is_string( $args ) && taxonomy_exists( $args ) || is_array( $args ) && wp_is_numeric_array( $args ) );
     1743
     1744    $defaults = array( 'hide_empty' => false );
     1745    if ( $use_legacy_args ) {
     1746        $defaults['taxonomy'] = $args;
     1747        $args                 = $deprecated;
     1748    }
     1749
     1750    $args = wp_parse_args( $args, $defaults );
    17451751
    17461752    // Backward compatibility.
Note: See TracChangeset for help on using the changeset viewer.