diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 8d7b6c0961..2dea874b37 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -199,10 +199,19 @@ case 'add-cat' : // From Manage->Categories $x->send(); } - if ( !$cat = wp_insert_category( $_POST ) ) - die('0'); - if ( !$cat = get_category( $cat ) ) + $cat = wp_insert_category( $_POST, true ); + + if ( is_wp_error($cat) ) { + $x = new WP_Ajax_Response( array( + 'what' => 'cat', + 'id' => $cat + ) ); + $x->send(); + } + + if ( !$cat || (!$cat = get_category( $cat )) ) die('0'); + $level = 0; $cat_full_name = $cat->name; $_cat = $cat; diff --git a/wp-admin/includes/taxonomy.php b/wp-admin/includes/taxonomy.php index 3f70f45b8d..df8c80ae72 100644 --- a/wp-admin/includes/taxonomy.php +++ b/wp-admin/includes/taxonomy.php @@ -52,7 +52,7 @@ function wp_delete_category($cat_ID) { return wp_delete_term($cat_ID, 'category', "default=$default"); } -function wp_insert_category($catarr) { +function wp_insert_category($catarr, $wp_error = false) { global $wpdb; extract($catarr, EXTR_SKIP); @@ -84,8 +84,12 @@ function wp_insert_category($catarr) { else $cat_ID = wp_insert_term($cat_name, 'category', $args); - if ( is_wp_error($cat_ID) ) - return 0; + if ( is_wp_error($cat_ID) ) { + if ( $wp_error ) + return $cat_ID; + else + return 0; + } return $cat_ID['term_id']; }