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/src/wp-includes/taxonomy.php

    r48358 r48480  
    507507    $taxonomy_object->remove_hooks();
    508508
     509    // Remove custom taxonomy default term option.
     510    if ( ! empty( $taxonomy_object->default_term ) ) {
     511        delete_option( 'default_taxonomy_' . $taxonomy_object->name );
     512    }
     513
    509514    // Remove the taxonomy.
    510515    unset( $wp_taxonomies[ $taxonomy ] );
     
    18251830    }
    18261831
     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
    18271841    $args = wp_parse_args( $args, $defaults );
    18281842
     
    25132527    }
    25142528
    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 
    25242529    if ( ! $append ) {
    25252530        $old_tt_ids = wp_get_object_terms(
Note: See TracChangeset for help on using the changeset viewer.