From 7d01ad3a4947afb891d6cb28aba7d6d5e7b7cac5 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 21 May 2010 16:03:35 +0000 Subject: [PATCH] Check for siblings only if term already exists in the same taxonomy. see #13119 git-svn-id: http://svn.automattic.com/wordpress/trunk@14783 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index b61cad10e..8117a2aac 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1608,9 +1608,9 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { if ( $term_id = is_term($slug) ) { $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); - // We've got an existing term, which matches the name of the new term: - if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name ) { - // Heirarchical, and it matches an existing term, Do not allow same "name" in the same level. + // We've got an existing term in the same taxonomy, which matches the name of the new term: + if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && is_term( (int) $term_id, $taxonomy ) ) { + // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level. $siblings = get_terms($taxonomy, array('fields' => 'names', 'get' => 'all', 'parent' => (int)$parent) ); if ( in_array($name, $siblings) ) { return new WP_Error('term_exists', __('A term with the name provided already exists with this parent.')); @@ -1621,7 +1621,7 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { $term_id = (int) $wpdb->insert_id; } } elseif ( $existing_term['name'] != $name ) { - // We've got an existing term, with a different name, Creat ethe new term. + // We've got an existing term, with a different name, Create the new term. $slug = wp_unique_term_slug($slug, (object) $args); if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error);