From e45ee36b840dbde22b8ac94ff894cf29f1a4fd42 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 21 Apr 2017 19:14:44 +0000 Subject: [PATCH] Restore support for taxonomy 'args' override when querying object terms. [7520] introduced an undocumented feature whereby developers could register a custom taxonomy with an 'args' parameter, consisting of an array of config params that, when present, override corresponding params in the `$args` array passed to `wp_get_object_terms()` when using that function to query for terms in the specified taxonomy. The `wp_get_object_terms()` refactor in [38667] failed to respect this secret covenant, and the current changeset atones for the transgression. Props danielbachhuber. Fixes #40496. Built from https://develop.svn.wordpress.org/trunk@40513 git-svn-id: http://core.svn.wordpress.org/trunk@40389 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 22 +++++++++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 94f36689fd..f1c1bce307 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1841,10 +1841,30 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { $args = wp_parse_args( $args ); + /* + * When one or more queried taxonomies is registered with an 'args' array, + * those params override the `$args` passed to this function. + */ + $terms = array(); + if ( count( $taxonomies ) > 1 ) { + foreach ( $taxonomies as $index => $taxonomy ) { + $t = get_taxonomy( $taxonomy ); + if ( isset( $t->args ) && is_array( $t->args ) && $args != array_merge( $args, $t->args ) ) { + unset( $taxonomies[ $index ] ); + $terms = array_merge( $terms, wp_get_object_terms( $object_ids, $taxonomy, array_merge( $args, $t->args ) ) ); + } + } + } else { + $t = get_taxonomy( $taxonomies[0] ); + if ( isset( $t->args ) && is_array( $t->args ) ) { + $args = array_merge( $args, $t->args ); + } + } + $args['taxonomy'] = $taxonomies; $args['object_ids'] = $object_ids; - $terms = get_terms( $args ); + $terms = array_merge( $terms, get_terms( $args ) ); /** * Filters the terms for a given object or objects. diff --git a/wp-includes/version.php b/wp-includes/version.php index 7ce27a39a1..3f07a323d1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.8-alpha-40511'; +$wp_version = '4.8-alpha-40513'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.