diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 899bc87b9f..70c465a8ad 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -537,6 +537,9 @@ function register_taxonomy_for_object_type( $taxonomy, $object_type) { if ( ! in_array( $object_type, $wp_taxonomies[$taxonomy]->object_type ) ) $wp_taxonomies[$taxonomy]->object_type[] = $object_type; + // Filter out empties. + $wp_taxonomies[ $taxonomy ]->object_type = array_filter( $wp_taxonomies[ $taxonomy ]->object_type ); + return true; } diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index 4280928332..440df6a531 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -238,6 +238,19 @@ class Tests_Taxonomy extends WP_UnitTestCase { _unregister_post_type( $post_type ); } + + /** + * @ticket 32590 + */ + public function test_register_taxonomy_for_post_type_for_taxonomy_with_no_object_type_should_filter_out_empty_object_types() { + register_taxonomy( 'wptests_tax', '' ); + register_taxonomy_for_object_type( 'wptests_tax', 'post' ); + $tax = get_taxonomy( 'wptests_tax' ); + + $expected = array( 'post' ); + $this->assertEqualSets( $expected, $tax->object_type ); + } + /** * @ticket 25706 */