diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php
index e0acadcf87..31558d9898 100644
|
|
function unregister_taxonomy( $taxonomy ) { |
506 | 506 | $taxonomy_object->remove_rewrite_rules(); |
507 | 507 | $taxonomy_object->remove_hooks(); |
508 | 508 | |
| 509 | // Remove custom taxonomy default term option. |
| 510 | if ( ! empty( $taxonomy_object->default_term ) ) { |
| 511 | delete_option( 'default_taxonomy_' . $taxonomy_object->name ); |
| 512 | } |
| 513 | |
509 | 514 | // Remove the taxonomy. |
510 | 515 | unset( $wp_taxonomies[ $taxonomy ] ); |
511 | 516 | |
… |
… |
function wp_delete_term( $term, $taxonomy, $args = array() ) { |
1824 | 1829 | } |
1825 | 1830 | } |
1826 | 1831 | |
| 1832 | // Don't delete the default custom taxonomy term. |
| 1833 | $taxonomy_object = get_taxonomy( $taxonomy ); |
| 1834 | if ( ! empty( $taxonomy_object->default_term ) ) { |
| 1835 | $defaults['default'] = (int) get_option( 'default_taxonomy_' . $taxonomy ); |
| 1836 | if ( $defaults['default'] === $term ) { |
| 1837 | return 0; |
| 1838 | } |
| 1839 | } |
| 1840 | |
1827 | 1841 | $args = wp_parse_args( $args, $defaults ); |
1828 | 1842 | |
1829 | 1843 | if ( isset( $args['default'] ) ) { |
… |
… |
function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { |
2516 | 2530 | $taxonomy_obj = get_taxonomy( $taxonomy ); |
2517 | 2531 | |
2518 | 2532 | // Default term for this taxonomy. |
2519 | | $default_term_id = get_option( 'default_taxonomy_' . $taxonomy ); |
2520 | | if ( empty( $terms ) && ! empty( $taxonomy_obj->default_term ) && ! empty( $default_term_id ) ) { |
2521 | | $terms[] = (int) $default_term_id; |
| 2533 | if ( empty( $terms ) && ! empty( $taxonomy_obj->default_term ) ) { |
| 2534 | $default_term_id = get_option( 'default_taxonomy_' . $taxonomy ); |
| 2535 | if ( ! empty( $default_term_id ) ) { |
| 2536 | $terms[] = (int) $default_term_id; |
| 2537 | } |
2522 | 2538 | } |
2523 | 2539 | |
2524 | 2540 | if ( ! $append ) { |
diff --git tests/phpunit/tests/taxonomy.php tests/phpunit/tests/taxonomy.php
index 7a5a065be1..d2972729ca 100644
|
|
class Tests_Taxonomy extends WP_UnitTestCase { |
999 | 999 | ) |
1000 | 1000 | ); |
1001 | 1001 | |
| 1002 | // Test default category. |
1002 | 1003 | $term = wp_get_post_terms( $post_id, $tax ); |
1003 | 1004 | $this->assertSame( get_option( 'default_taxonomy_' . $tax ), $term[0]->term_id ); |
1004 | 1005 | |
| 1006 | // Test default term deletion. |
| 1007 | $this->assertSame( wp_delete_term( $term[0]->term_id, $tax ), 0 ); |
| 1008 | |
1005 | 1009 | // Add custom post type. |
1006 | 1010 | register_post_type( |
1007 | 1011 | 'post-custom-tax', |
… |
… |
class Tests_Taxonomy extends WP_UnitTestCase { |
1017 | 1021 | ); |
1018 | 1022 | $term = wp_get_post_terms( $post_id, $tax ); |
1019 | 1023 | $this->assertSame( get_option( 'default_taxonomy_' . $tax ), $term[0]->term_id ); |
| 1024 | |
| 1025 | unregister_taxonomy( $tax ); |
| 1026 | $this->assertSame( get_option( 'default_taxonomy_' . $tax ), false ); |
1020 | 1027 | } |
1021 | 1028 | } |