Ticket #6211: same-slug-diff-taxonomy-2.patch

File same-slug-diff-taxonomy-2.patch, 1.7 KB (added by nerrad, 4 years ago)

adds BOOL canonical param to $args for wp_insert_term

  • wp-includes/taxonomy.php

     
    11241124        if ( is_int($term) && 0 == $term ) 
    11251125                return new WP_Error('invalid_term_id', __('Invalid term ID')); 
    11261126 
    1127         $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => ''); 
     1127        $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '', 'canonical' => true); 
    11281128        $args = wp_parse_args($args, $defaults); 
    11291129        $args['name'] = $term; 
    11301130        $args['taxonomy'] = $taxonomy; 
     
    11511151                } 
    11521152        } 
    11531153 
    1154         if ( ! $term_id = is_term($slug) ) { 
    1155                 $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ); 
    1156                 $term_id = (int) $wpdb->insert_id; 
    1157         } else if ( is_taxonomy_hierarchical($taxonomy) && !empty($parent) ) { 
     1154        if ( $canonical ) { 
     1155                if ( ! $term_id = is_term($slug) ) { 
     1156                        $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ); 
     1157                        $term_id = (int) $wpdb->insert_id; 
     1158                }        
     1159        } else { 
     1160                if ( ! $term_id = is_term($slug, $taxonomy) ) { 
     1161                        $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ); 
     1162                        $term_id = (int) $wpdb->insert_id; 
     1163                        } 
     1164        } 
     1165         
     1166        if ( is_taxonomy_hierarchical($taxonomy) && !empty($parent) ) { 
    11581167                // If the taxonomy supports hierarchy and the term has a parent, make the slug unique 
    11591168                // by incorporating parent slugs. 
    11601169                $slug = wp_unique_term_slug($slug, (object) $args); 
     
    11621171                $term_id = (int) $wpdb->insert_id; 
    11631172        } 
    11641173 
     1174        if ( is_array($term_id) )  
     1175            $term_id = $term_id['term_id']; 
     1176         
    11651177        if ( empty($slug) ) { 
    11661178                $slug = sanitize_title($slug, $term_id); 
    11671179                $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) );