Output WP_Error message when adding categories via AJAX. fixes #5342

git-svn-id: http://svn.automattic.com/wordpress/trunk@6329 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-11-12 19:12:49 +00:00
parent fc31e5395b
commit 26cd478bb7
2 changed files with 19 additions and 6 deletions

View File

@ -199,10 +199,19 @@ case 'add-cat' : // From Manage->Categories
$x->send(); $x->send();
} }
if ( !$cat = wp_insert_category( $_POST ) ) $cat = wp_insert_category( $_POST, true );
die('0');
if ( !$cat = get_category( $cat ) ) 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'); die('0');
$level = 0; $level = 0;
$cat_full_name = $cat->name; $cat_full_name = $cat->name;
$_cat = $cat; $_cat = $cat;

View File

@ -52,7 +52,7 @@ function wp_delete_category($cat_ID) {
return wp_delete_term($cat_ID, 'category', "default=$default"); return wp_delete_term($cat_ID, 'category', "default=$default");
} }
function wp_insert_category($catarr) { function wp_insert_category($catarr, $wp_error = false) {
global $wpdb; global $wpdb;
extract($catarr, EXTR_SKIP); extract($catarr, EXTR_SKIP);
@ -84,8 +84,12 @@ function wp_insert_category($catarr) {
else else
$cat_ID = wp_insert_term($cat_name, 'category', $args); $cat_ID = wp_insert_term($cat_name, 'category', $args);
if ( is_wp_error($cat_ID) ) if ( is_wp_error($cat_ID) ) {
if ( $wp_error )
return $cat_ID;
else
return 0; return 0;
}
return $cat_ID['term_id']; return $cat_ID['term_id'];
} }