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();
}
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;

View File

@ -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'];
}