From caa1f1f88d1c913bef798961400c30227cb96ea9 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Mon, 12 Dec 2016 05:46:37 +0000 Subject: [PATCH] Taxonomy: Restore the ability to use string-based `$args` in `wp_get_object_terms()`. Props tyxla. Fixes #39215 git-svn-id: https://develop.svn.wordpress.org/trunk@39578 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/taxonomy.php | 2 ++ tests/phpunit/tests/term/wpGetObjectTerms.php | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index bed3894334..7fa4076acf 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -1877,6 +1877,8 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { $object_ids = array($object_ids); $object_ids = array_map('intval', $object_ids); + $args = wp_parse_args( $args ); + $args['taxonomy'] = $taxonomies; $args['object_ids'] = $object_ids; diff --git a/tests/phpunit/tests/term/wpGetObjectTerms.php b/tests/phpunit/tests/term/wpGetObjectTerms.php index a03550157c..95c8abcb62 100644 --- a/tests/phpunit/tests/term/wpGetObjectTerms.php +++ b/tests/phpunit/tests/term/wpGetObjectTerms.php @@ -690,4 +690,27 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase { // all terms should still be objects return $terms; } + + public function test_verify_args_parameter_can_be_string() { + $p = self::factory()->post->create(); + + $t1 = self::factory()->term->create( array( + 'taxonomy' => $this->taxonomy, + 'name' => 'AAA', + ) ); + $t2 = self::factory()->term->create( array( + 'taxonomy' => $this->taxonomy, + 'name' => 'ZZZ', + ) ); + $t3 = self::factory()->term->create( array( + 'taxonomy' => $this->taxonomy, + 'name' => 'JJJ', + ) ); + + wp_set_object_terms( $p, array( $t1, $t2, $t3 ), $this->taxonomy ); + + $found = wp_get_object_terms( $p, $this->taxonomy, 'orderby=name&fields=ids' ); + + $this->assertEquals( array( $t1, $t3, $t2 ), $found ); + } }