Make WordPress Core

Changeset 32709


Ignore:
Timestamp:
06/08/2015 07:44:32 PM (11 years ago)
Author:
boonebgorges
Message:

Filter out empty object_types in register_taxonomy_for_object_type().

This prevents weird edge bugs when registering an existing taxonomy with an
object type when the taxonomy was previously associated with no object types.

Fixes #32590.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r32627 r32709  
    537537        if ( ! in_array( $object_type, $wp_taxonomies[$taxonomy]->object_type ) )
    538538                $wp_taxonomies[$taxonomy]->object_type[] = $object_type;
     539
     540        // Filter out empties.
     541        $wp_taxonomies[ $taxonomy ]->object_type = array_filter( $wp_taxonomies[ $taxonomy ]->object_type );
    539542
    540543        return true;
  • trunk/tests/phpunit/tests/taxonomy.php

    r31457 r32709  
    239239
    240240        }
     241
     242        /**
     243         * @ticket 32590
     244         */
     245        public function test_register_taxonomy_for_post_type_for_taxonomy_with_no_object_type_should_filter_out_empty_object_types() {
     246                register_taxonomy( 'wptests_tax', '' );
     247                register_taxonomy_for_object_type( 'wptests_tax', 'post' );
     248                $tax = get_taxonomy( 'wptests_tax' );
     249
     250                $expected = array( 'post' );
     251                $this->assertEqualSets( $expected, $tax->object_type );
     252        }
     253
    241254        /**
    242255         * @ticket 25706
Note: See TracChangeset for help on using the changeset viewer.