diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 4c501af5e6..0939b27fdd 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1630,11 +1630,11 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { if ( $term_id = term_exists($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 in the same taxonomy, which matches the name of the new term: - if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && term_exists( (int) $term_id, $taxonomy ) ) { + if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && $exists = term_exists( (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.')); + return new WP_Error('term_exists', __('A term with the name provided already exists with this parent.'), $exists['term_id']); } else { $slug = wp_unique_term_slug($slug, (object) $args); if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) @@ -1647,9 +1647,9 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { 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); $term_id = (int) $wpdb->insert_id; - } elseif ( term_exists( (int) $term_id, $taxonomy ) ) { + } elseif ( $exists = term_exists( (int) $term_id, $taxonomy ) ) { // Same name, same slug. - return new WP_Error('term_exists', __('A term with the name provided already exists.')); + return new WP_Error('term_exists', __('A term with the name provided already exists.'), $exists['term_id']); } } else { // This term does not exist at all in the database, Create it. diff --git a/xmlrpc.php b/xmlrpc.php index fd471f26ee..fdd670e233 100644 --- a/xmlrpc.php +++ b/xmlrpc.php @@ -933,9 +933,15 @@ class wp_xmlrpc_server extends IXR_Server { "category_description" => $category["description"] ); - $cat_id = wp_insert_category($new_category); - if ( !$cat_id ) + $cat_id = wp_insert_category($new_category, true); + if ( is_wp_error( $cat_id ) ) { + if ( 'term_exists' == $cat_id->get_error_code() ) + return (int) $cat_id->get_error_data(); + else + return(new IXR_Error(500, __("Sorry, the new category failed."))); + } elseif ( ! $cat_id ) { return(new IXR_Error(500, __("Sorry, the new category failed."))); + } return($cat_id); }