From 036c33caaad9f7d8be3f04060863ac4c20520994 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 8 Jun 2015 19:44:32 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@32709 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/taxonomy.php | 3 +++ tests/phpunit/tests/taxonomy.php | 13 +++++++++++++ 2 files changed, 16 insertions(+) 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 */