Changeset 48480
- Timestamp:
- 07/14/2020 04:39:44 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r48462 r48480 4037 4037 if ( 'auto-draft' !== $post_status ) { 4038 4038 foreach ( get_object_taxonomies( $post_type, 'object' ) as $taxonomy => $tax_object ) { 4039 if ( ! empty( $tax_object->default_term ) && ( empty( $postarr['tax_input'] ) || ! isset( $postarr['tax_input'][ $taxonomy ] ) ) ) { 4040 $postarr['tax_input'][ $taxonomy ] = array(); 4039 4040 if ( ! empty( $tax_object->default_term ) ) { 4041 4042 // Filter out empty terms. 4043 if ( isset( $postarr['tax_input'] ) && is_array( $postarr['tax_input'][ $taxonomy ] ) ) { 4044 $postarr['tax_input'][ $taxonomy ] = array_filter( $postarr['tax_input'][ $taxonomy ] ); 4045 } 4046 4047 // Passed custom taxonomy list overwrites existing list if not empty. 4048 $terms = wp_get_object_terms( $post_ID, $taxonomy, array( 'fields' => 'ids' ) ); 4049 if ( ! empty( $terms ) && empty( $postarr['tax_input'][ $taxonomy ] ) ) { 4050 $postarr['tax_input'][ $taxonomy ] = $terms; 4051 } 4052 4053 if ( empty( $postarr['tax_input'][ $taxonomy ] ) ) { 4054 $default_term_id = get_option( 'default_taxonomy_' . $taxonomy ); 4055 if ( ! empty( $default_term_id ) ) { 4056 $postarr['tax_input'][ $taxonomy ] = array( (int) $default_term_id ); 4057 } 4058 } 4041 4059 } 4042 4060 } -
trunk/src/wp-includes/taxonomy.php
r48358 r48480 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 ] ); … … 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 … … 2513 2527 } 2514 2528 2515 // Add default term.2516 $taxonomy_obj = get_taxonomy( $taxonomy );2517 2518 // 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;2522 }2523 2524 2529 if ( ! $append ) { 2525 2530 $old_tt_ids = wp_get_object_terms( -
trunk/tests/phpunit/tests/taxonomy.php
r48356 r48480 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 ); 1005 1006 // Test default term deletion. 1007 $this->assertSame( wp_delete_term( $term[0]->term_id, $tax ), 0 ); 1004 1008 1005 1009 // Add custom post type. … … 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 // wp_set_object_terms shouldn't assign default category. 1026 wp_set_object_terms( $post_id, array(), $tax ); 1027 $term = wp_get_post_terms( $post_id, $tax ); 1028 $this->assertSame( array(), $term ); 1029 1030 unregister_taxonomy( $tax ); 1031 $this->assertSame( get_option( 'default_taxonomy_' . $tax ), false ); 1020 1032 } 1021 1033 }
Note: See TracChangeset
for help on using the changeset viewer.