Make WordPress Core


Ignore:
Timestamp:
07/14/2020 04:39:44 PM (5 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/taxonomy.php

    r48356 r48480  
    10001000        );
    10011001
     1002        // Test default category.
    10021003        $term = wp_get_post_terms( $post_id, $tax );
    10031004        $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 );
    10041008
    10051009        // Add custom post type.
     
    10181022        $term    = wp_get_post_terms( $post_id, $tax );
    10191023        $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 );
    10201032    }
    10211033}
Note: See TracChangeset for help on using the changeset viewer.