Make WordPress Core

Changeset 19792


Ignore:
Timestamp:
01/30/2012 06:19:27 PM (13 years ago)
Author:
ryan
Message:

Check the return of wp_insert_term() for WP_Error or array. Prevents fatal erros and failure to add categories when adding terms via ajax. Props mdawaffe. fixes #17938 #17939

File:
1 edited

Legend:

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

    r19738 r19792  
    235235        if ( '' === $category_nicename )
    236236            continue;
    237         if ( !($cat_id = term_exists($cat_name, $taxonomy->name, $parent)) ) {
    238             $new_term = wp_insert_term($cat_name, $taxonomy->name, array('parent' => $parent));
    239             $cat_id = $new_term['term_id'];
    240         }
     237        if ( !$cat_id = term_exists( $cat_name, $taxonomy->name, $parent ) )
     238            $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) );
     239        if ( is_wp_error( $cat_id ) )
     240            continue;
     241        else if ( is_array( $cat_id ) )
     242            $cat_id = $cat_id['term_id'];
    241243        $checked_categories[] = $cat_id;
    242244        if ( $parent ) // Do these all at once in a second
     
    489491        if ( '' === $slug )
    490492            continue;
    491         if ( !$cat_id = term_exists( $cat_name, 'link_category' ) ) {
     493        if ( !$cat_id = term_exists( $cat_name, 'link_category' ) )
    492494            $cat_id = wp_insert_term( $cat_name, 'link_category' );
    493         }
    494         $cat_id = $cat_id['term_id'];
     495        if ( is_wp_error( $cat_id ) )
     496            continue;
     497        else if ( is_array( $cat_id ) )
     498            $cat_id = $cat_id['term_id'];
    495499        $cat_name = esc_html(stripslashes($cat_name));
    496500        $x->add( array(
Note: See TracChangeset for help on using the changeset viewer.