Make WordPress Core

Ticket #41010: 41010.3.patch

File 41010.3.patch, 2.0 KB (added by boonebgorges, 6 years ago)
  • src/wp-includes/taxonomy.php

    diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php
    index 05c6a10e8e..79d18f5fcd 100644
    a b function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { 
    19171917        $args['taxonomy'] = $taxonomies;
    19181918        $args['object_ids'] = $object_ids;
    19191919
    1920         $terms = array_merge( $terms, get_terms( $args ) );
     1920        // Taxonomies registered without an 'args' param are handled here.
     1921        if ( ! empty( $taxonomies ) ) {
     1922                $terms = array_merge( $terms, get_terms( $args ) );
     1923        }
    19211924
    19221925        /**
    19231926         * Filters the terms for a given object or objects.
  • tests/phpunit/tests/term/wpGetObjectTerms.php

    diff --git a/tests/phpunit/tests/term/wpGetObjectTerms.php b/tests/phpunit/tests/term/wpGetObjectTerms.php
    index e527a601bf..5e3b8bcb9b 100644
    a b class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase { 
    760760                $args['orderby'] = 'term_order';
    761761                return $args;
    762762        }
     763
     764        /**
     765         * @ticket 41010
     766         */
     767        public function test_duplicate_terms_should_not_be_returned_when_passed_multiple_taxonomies_registered_with_args_array() {
     768                $taxonomy1 = 'wptests_tax';
     769                $taxonomy2 = 'wptests_tax_2';
     770
     771                // Any non-empty 'args' array triggers the bug.
     772                $taxonomy_arguments = array(
     773                        'args' => array( 0 ),
     774                );
     775
     776                register_taxonomy( $taxonomy1, 'post', $taxonomy_arguments );
     777                register_taxonomy( $taxonomy2, 'post', $taxonomy_arguments );
     778
     779                $post_id = self::factory()->post->create();
     780                $term_1_id = self::factory()->term->create( array(
     781                        'taxonomy' => $taxonomy1,
     782                ) );
     783                $term_2_id = self::factory()->term->create( array(
     784                        'taxonomy' => $taxonomy2,
     785                ) );
     786
     787                wp_set_object_terms( $post_id, $term_1_id, $taxonomy1 );
     788                wp_set_object_terms( $post_id, $term_2_id, $taxonomy2 );
     789
     790                $expected = array( $term_1_id, $term_2_id );
     791
     792                $actual = wp_get_object_terms( $post_id, array( $taxonomy1, $taxonomy2 ), array(
     793                        'orderby' => 'term_id',
     794                        'fields' => 'ids',
     795                ) );
     796
     797                $this->assertEqualSets( $expected, $actual );
     798        }
    763799}