Make WordPress Core

Changeset 6329


Ignore:
Timestamp:
11/12/2007 07:12:49 PM (16 years ago)
Author:
ryan
Message:

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

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r6303 r6329  
    200200    }
    201201
    202     if ( !$cat = wp_insert_category( $_POST ) )
    203         die('0');
    204     if ( !$cat = get_category( $cat ) )
    205         die('0');
     202    $cat = wp_insert_category( $_POST, true );
     203
     204    if ( is_wp_error($cat) ) {
     205        $x = new WP_Ajax_Response( array(
     206            'what' => 'cat',
     207            'id' => $cat
     208        ) );
     209        $x->send();
     210    }
     211
     212    if ( !$cat || (!$cat = get_category( $cat )) )
     213        die('0');
     214
    206215    $level = 0;
    207216    $cat_full_name = $cat->name;
  • trunk/wp-admin/includes/taxonomy.php

    r6157 r6329  
    5353}
    5454
    55 function wp_insert_category($catarr) {
     55function wp_insert_category($catarr, $wp_error = false) {
    5656    global $wpdb;
    5757
     
    8585        $cat_ID = wp_insert_term($cat_name, 'category', $args);
    8686
    87     if ( is_wp_error($cat_ID) )
    88         return 0;
     87    if ( is_wp_error($cat_ID) ) {
     88        if ( $wp_error )
     89            return $cat_ID;
     90        else
     91            return 0;
     92    }
    8993
    9094    return $cat_ID['term_id'];
Note: See TracChangeset for help on using the changeset viewer.