Taxonomy: Make some adjustments to handling default terms for custom taxonomies:

* Move default term assignment from `wp_set_object_terms()` to `wp_insert_post()`.
* Make sure the passed taxonomy list overwrites the existing list if not empty.
* Remove the default term option on `unregister_taxonomy()`.
* Prevent deletion of the default term in `wp_delete_term()`.

Props enrico.sorcinelli, TimothyBlynJacobs.
See #43517.

git-svn-id: https://develop.svn.wordpress.org/trunk@48480 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-07-14 16:39:44 +00:00
parent 9181ecff85
commit c843cf19c3
3 changed files with 46 additions and 11 deletions
+12
View File
@@ -999,9 +999,13 @@ class Tests_Taxonomy extends WP_UnitTestCase {
)
);
// Test default category.
$term = wp_get_post_terms( $post_id, $tax );
$this->assertSame( get_option( 'default_taxonomy_' . $tax ), $term[0]->term_id );
// Test default term deletion.
$this->assertSame( wp_delete_term( $term[0]->term_id, $tax ), 0 );
// Add custom post type.
register_post_type(
'post-custom-tax',
@@ -1017,5 +1021,13 @@ class Tests_Taxonomy extends WP_UnitTestCase {
);
$term = wp_get_post_terms( $post_id, $tax );
$this->assertSame( get_option( 'default_taxonomy_' . $tax ), $term[0]->term_id );
// wp_set_object_terms shouldn't assign default category.
wp_set_object_terms( $post_id, array(), $tax );
$term = wp_get_post_terms( $post_id, $tax );
$this->assertSame( array(), $term );
unregister_taxonomy( $tax );
$this->assertSame( get_option( 'default_taxonomy_' . $tax ), false );
}
}