Ticket #6211: same-slug-diff-taxonomy-2.patch
| File same-slug-diff-taxonomy-2.patch, 1.7 KB (added by nerrad, 4 years ago) |
|---|
-
wp-includes/taxonomy.php
1124 1124 if ( is_int($term) && 0 == $term ) 1125 1125 return new WP_Error('invalid_term_id', __('Invalid term ID')); 1126 1126 1127 $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '' );1127 $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '', 'canonical' => true); 1128 1128 $args = wp_parse_args($args, $defaults); 1129 1129 $args['name'] = $term; 1130 1130 $args['taxonomy'] = $taxonomy; … … 1151 1151 } 1152 1152 } 1153 1153 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) ) { 1158 1167 // If the taxonomy supports hierarchy and the term has a parent, make the slug unique 1159 1168 // by incorporating parent slugs. 1160 1169 $slug = wp_unique_term_slug($slug, (object) $args); … … 1162 1171 $term_id = (int) $wpdb->insert_id; 1163 1172 } 1164 1173 1174 if ( is_array($term_id) ) 1175 $term_id = $term_id['term_id']; 1176 1165 1177 if ( empty($slug) ) { 1166 1178 $slug = sanitize_title($slug, $term_id); 1167 1179 $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) );
