Changeset 63488 for trunk/src/wp-includes/taxonomy.php
- Timestamp:
- 09/05/2026 01:39:01 AM (2 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/taxonomy.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r63426 r63488 1310 1310 * @since 4.8.0 Introduced 'suppress_filter' parameter. 1311 1311 * 1312 * @param array|string $args Optional. Array or string of arguments. See WP_Term_Query::__construct()1312 * @param array|string $args Optional. Array or string of arguments. See {@see WP_Term_Query::__construct()} 1313 1313 * for information on accepted arguments. Default empty array. 1314 1314 * @param array|string $deprecated Optional. Argument array, when using the legacy function parameter format. … … 1316 1316 * function parameter will be parsed as a taxonomy or array of taxonomies. 1317 1317 * Default empty. 1318 * @return WP_Term[]|int[]|string[]|string|WP_Error Array of terms, a count thereof as a numeric string, 1319 * or WP_Error if any of the taxonomies do not exist. 1320 * See the function description for more information. 1318 * @return WP_Term[]|int[]|string[]|int|string|WP_Error Array of terms, a count thereof as a numeric string, 1319 * the integer 0 when the queried parent term is not in 1320 * the taxonomy hierarchy, or WP_Error if any of the 1321 * taxonomies do not exist. See the function description 1322 * for more information. 1323 * 1324 * @phpstan-return ( 1325 * $args is array{ fields: 'count', ... } 1326 * ? 0|numeric-string|WP_Error 1327 * : ( $args is array{ fields: 'ids'|'tt_ids', ... } 1328 * ? int[]|WP_Error 1329 * : ( $args is array{ fields: 'id=>parent', ... } 1330 * ? array<int, int>|WP_Error 1331 * : ( $args is array{ fields: 'names'|'slugs', ... } 1332 * ? string[]|WP_Error 1333 * : ( $args is array{ fields: 'id=>name'|'id=>slug', ... } 1334 * ? array<int, string>|WP_Error 1335 * : ( $deprecated is '' 1336 * ? ( $args is array 1337 * ? WP_Term[]|WP_Error 1338 * : WP_Term[]|int[]|string[]|int|string|WP_Error ) 1339 * : WP_Term[]|int[]|string[]|int|string|WP_Error ) ) ) ) ) 1340 * ) 1321 1341 */ 1322 1342 function get_terms( $args = array(), $deprecated = '' ) { … … 1958 1978 * @since 5.6.0 Changed the function signature so that the `$args` array can be provided as the first parameter. 1959 1979 * 1960 * @param array|string $args Optional. Array or string of arguments. See WP_Term_Query::__construct()1980 * @param array|string $args Optional. Array or string of arguments. See {@see WP_Term_Query::__construct()} 1961 1981 * for information on accepted arguments. Default empty array. 1962 1982 * @param array|string $deprecated Optional. Argument array, when using the legacy function parameter format. … … 1964 1984 * function parameter will be parsed as a taxonomy or array of taxonomies. 1965 1985 * Default empty. 1966 * @return string|WP_Error Numeric string containing the number of terms in that 1967 * taxonomy or WP_Error if the taxonomy does not exist. 1986 * @return string|int|WP_Error Numeric string containing the number of terms in that taxonomy, 1987 * the integer 0 when the queried parent term is not in the taxonomy 1988 * hierarchy, or WP_Error if the taxonomy does not exist. 1989 * @phpstan-return numeric-string|0|WP_Error 1968 1990 */ 1969 1991 function wp_count_terms( $args = array(), $deprecated = '' ) { … … 1993 2015 } 1994 2016 1995 $args['fields'] = 'count'; 2017 $args = array_merge( 2018 $args, 2019 array( 'fields' => 'count' ) 2020 ); 1996 2021 1997 2022 return get_terms( $args ); … … 2290 2315 * @since 6.3.0 Passing `update_term_meta_cache` argument value false by default resulting in get_terms() to not 2291 2316 * prime the term meta cache. 2317 * @since 7.2.0 A count is returned as a numeric string when `$fields` is 'count'. Previously requesting 2318 * a count resulted in an error. 2292 2319 * 2293 2320 * @param int|int[] $object_ids The ID(s) of the object(s) to retrieve. 2294 2321 * @param string|string[] $taxonomies The taxonomy names to retrieve terms from. 2295 * @param array|string $args See WP_Term_Query::__construct()for supported arguments.2322 * @param array|string $args See {@see WP_Term_Query::__construct()} for supported arguments. 2296 2323 * @return WP_Term[]|int[]|string[]|string|WP_Error Array of terms, a count thereof as a numeric string, 2297 2324 * or WP_Error if any of the taxonomies do not exist. 2298 * See WP_Term_Query::get_terms() for more information. 2325 * See {@see WP_Term_Query::get_terms()} for more information. 2326 * 2327 * @phpstan-return ( 2328 * $args is array{ fields: 'count', ... } 2329 * ? numeric-string|WP_Error 2330 * : ( $args is array{ fields: 'ids'|'tt_ids', ... } 2331 * ? int[]|WP_Error 2332 * : ( $args is array{ fields: 'id=>parent', ... } 2333 * ? array<int, int>|WP_Error 2334 * : ( $args is array{ fields: 'names'|'slugs', ... } 2335 * ? string[]|WP_Error 2336 * : ( $args is array{ fields: 'id=>name'|'id=>slug', ... } 2337 * ? array<int, string>|WP_Error 2338 * : ( $args is array 2339 * ? WP_Term[]|WP_Error 2340 * : WP_Term[]|int[]|string[]|string|WP_Error ) ) ) ) ) 2341 * ) 2299 2342 */ 2300 2343 function wp_get_object_terms( $object_ids, $taxonomies, $args = array() ) { 2344 $args = wp_parse_args( $args ); 2345 2301 2346 if ( empty( $object_ids ) || empty( $taxonomies ) ) { 2347 if ( isset( $args['fields'] ) && 'count' === $args['fields'] ) { 2348 return '0'; 2349 } 2350 2302 2351 return array(); 2303 2352 } … … 2339 2388 * When one or more queried taxonomies is registered with an 'args' array, 2340 2389 * those params override the `$args` passed to this function. 2390 * 2391 * That array is for query modifiers such as 'orderby'. Overriding 'fields' 2392 * there does not work, because callers depend on the shape they asked for: 2393 * get_the_taxonomies() reads `$term->name` off the result, and 2394 * wp_set_object_terms() needs the 'tt_ids' it requested. A taxonomy that 2395 * overrides it also returns a different shape than the taxonomies queried 2396 * below, leaving the two merged into one another here. 2341 2397 */ 2342 2398 $terms = array(); … … 2346 2402 if ( isset( $t->args ) && is_array( $t->args ) && array_merge( $args, $t->args ) != $args ) { 2347 2403 unset( $taxonomies[ $index ] ); 2348 $terms = array_merge( $terms, wp_get_object_terms( $object_ids, $taxonomy, array_merge( $args, $t->args ) ) ); 2404 2405 // Cast because a count is returned as a numeric string. The counts are summed below. 2406 $terms_from_taxonomy = (array) wp_get_object_terms( $object_ids, $taxonomy, array_merge( $args, $t->args ) ); 2407 2408 // Array keys should be preserved for values of $fields that use term_id for keys. 2409 if ( ! empty( $args['fields'] ) && str_starts_with( $args['fields'], 'id=>' ) ) { 2410 $terms = $terms + $terms_from_taxonomy; 2411 } else { 2412 $terms = array_merge( $terms, $terms_from_taxonomy ); 2413 } 2349 2414 } 2350 2415 } … … 2361 2426 // Taxonomies registered without an 'args' param are handled here. 2362 2427 if ( ! empty( $taxonomies ) ) { 2363 $terms_from_remaining_taxonomies = get_terms( $args ); 2428 // Cast because a count is returned as a numeric string. The counts are summed below. 2429 $terms_from_remaining_taxonomies = (array) get_terms( $args ); 2364 2430 2365 2431 // Array keys should be preserved for values of $fields that use term_id for keys. … … 2371 2437 } 2372 2438 2439 if ( isset( $args['fields'] ) && 'count' === $args['fields'] ) { 2440 $terms = (string) array_sum( $terms ); 2441 } 2442 2373 2443 /** 2374 2444 * Filters the terms for a given object or objects. … … 2380 2450 * @param string[] $taxonomies Array of taxonomy names from which terms were retrieved. 2381 2451 * @param array $args Array of arguments for retrieving terms for the given 2382 * object(s). See wp_get_object_terms()for details.2452 * object(s). See {@see wp_get_object_terms()} for details. 2383 2453 */ 2384 2454 $terms = apply_filters( 'get_object_terms', $terms, $object_ids, $taxonomies, $args ); … … 2399 2469 * @param string $taxonomies SQL fragment of taxonomy names from which terms were retrieved. 2400 2470 * @param array $args Array of arguments for retrieving terms for the given 2401 * object(s). See wp_get_object_terms()for details.2471 * object(s). See {@see wp_get_object_terms()} for details. 2402 2472 */ 2403 2473 return apply_filters( 'wp_get_object_terms', $terms, $object_ids, $taxonomies, $args );
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)