Ticket #5342: inset_cat_wp_err.diff

File inset_cat_wp_err.diff, 1.3 KB (added by ryan, 5 years ago)
  • wp-admin/admin-ajax.php

     
    199199                $x->send(); 
    200200        } 
    201201 
    202         if ( !$cat = wp_insert_category( $_POST ) ) 
     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 )) ) 
    203213                die('0'); 
    204         if ( !$cat = get_category( $cat ) ) 
    205                 die('0'); 
     214 
    206215        $level = 0; 
    207216        $cat_full_name = $cat->name; 
    208217        $_cat = $cat; 
  • wp-admin/includes/taxonomy.php

     
    5252        return wp_delete_term($cat_ID, 'category', "default=$default"); 
    5353} 
    5454 
    55 function wp_insert_category($catarr) { 
     55function wp_insert_category($catarr, $wp_error = false) { 
    5656        global $wpdb; 
    5757 
    5858        extract($catarr, EXTR_SKIP); 
     
    8484        else 
    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']; 
    9195}