Ticket #36399: 36399.diff
File 36399.diff, 2.4 KB (added by , 8 years ago) |
---|
-
src/wp-includes/taxonomy.php
2182 2182 } 2183 2183 2184 2184 /** 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. 2186 2186 * 2187 2187 * Default $args is 'hide_empty' which can be 'hide_empty=true' or array('hide_empty' => true). 2188 2188 * 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 * 2189 2202 * @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. 2190 2204 * 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. 2194 2210 * @return array|int|WP_Error Number of terms in that taxonomy or WP_Error if the taxonomy does not exist. 2195 2211 */ 2196 function wp_count_terms( $ taxonomy, $args = array()) {2212 function wp_count_terms( $args = array(), $deprecated = '' ) { 2197 2213 $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 2198 2223 $args = wp_parse_args($args, $defaults); 2199 2224 2200 2225 // backwards compatibility … … 2205 2230 2206 2231 $args['fields'] = 'count'; 2207 2232 2208 return get_terms( $taxonomy, $args);2233 return get_terms( $args ); 2209 2234 } 2210 2235 2211 2236 /**