Make WordPress Core

Ticket #36399: 36399.diff

File 36399.diff, 2.4 KB (added by flixos90, 8 years ago)
  • src/wp-includes/taxonomy.php

     
    21822182}
    21832183
    21842184/**
    2185  * Count how many terms are in Taxonomy.
     2185 * Count how many terms are in a specific taxonomy or how many terms exist at all.
    21862186 *
    21872187 * Default $args is 'hide_empty' which can be 'hide_empty=true' or array('hide_empty' => true).
    21882188 *
     2189 * Prior to 4.6.0, the first parameter of `wp_count_terms()` was a taxonomy or list of taxonomies:
     2190 *
     2191 *     $terms = wp_count_terms( 'post_tag', array(
     2192 *         'hide_empty' => false,
     2193 *     ) );
     2194 *
     2195 * Since 4.6.0, taxonomies should be passed via the 'taxonomy' argument in the `$args` array:
     2196 *
     2197 *     $terms = wp_count_terms( array(
     2198 *         'taxonomy' => 'post_tag',
     2199 *         'hide_empty' => false,
     2200 *     ) );
     2201 *
    21892202 * @since 2.3.0
     2203 * @since 4.6.0 Changed the function signature so that the `$args` array can be provided as the first parameter.
    21902204 *
    2191  * @param string       $taxonomy Taxonomy name.
    2192  * @param array|string $args     Optional. Array of arguments that get passed to {@see get_terms()}.
    2193  *                               Default empty array.
     2205 * @param array|string $args       Optional. Array of arguments that get passed to {@see get_terms()}.
     2206 *                                 Default empty array.
     2207 * @param array        $deprecated Argument array, when using the legacy function parameter format. If present, this
     2208 *                                 parameter will be interpreted as `$args`, and the first function parameter will
     2209 *                                 be parsed as a taxonomy or array of taxonomies.
    21942210 * @return array|int|WP_Error Number of terms in that taxonomy or WP_Error if the taxonomy does not exist.
    21952211 */
    2196 function wp_count_terms( $taxonomy, $args = array() ) {
     2212function wp_count_terms( $args = array(), $deprecated = '' ) {
    21972213        $defaults = array('hide_empty' => false);
     2214
     2215        $is_sequential = count( array_filter( array_keys( (array) $args ), 'is_int' ) ) === count( (array) $args );
     2216        $do_legacy_args = $deprecated || $is_sequential;
     2217
     2218        if ( $do_legacy_args ) {
     2219                $deprecated['taxonomy'] = (array) $args;
     2220                $args = $deprecated;
     2221        }
     2222
    21982223        $args = wp_parse_args($args, $defaults);
    21992224
    22002225        // backwards compatibility
     
    22052230
    22062231        $args['fields'] = 'count';
    22072232
    2208         return get_terms($taxonomy, $args);
     2233        return get_terms( $args );
    22092234}
    22102235
    22112236/**