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
This commit is contained in:
parent
b3660e2731
commit
036c33caaa
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user