WordPress.org

Make WordPress Core

Changeset 39637


Ignore:
Timestamp:
12/23/16 03:10:36 (9 months ago)
Author:
boonebgorges
Message:

Taxonomy: Eliminate redundant and inaccurate dupe check when creating categories from post.php.

The term_exists() check is not needed because of existing dupe
checks in wp_insert_term(). Furthermore, term_exists() conflates
term names and sanitized slugs, so incorrectly marks terms like
'C' and 'C+' as duplicates of one another.

Props garyc40, SergeyBiryukov, kovshenin, MikeHansenMe.
Fixes #16567.

File:
1 edited

Legend:

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

    r39600 r39637  
    473473        if ( '' === $category_nicename ) 
    474474            continue; 
    475         if ( !$cat_id = term_exists( $cat_name, $taxonomy->name, $parent ) ) 
    476             $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); 
    477         if ( is_wp_error( $cat_id ) ) { 
     475 
     476        $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); 
     477        if ( ! $cat_id || is_wp_error( $cat_id ) ) { 
    478478            continue; 
    479         } elseif ( is_array( $cat_id ) ) { 
     479        } else { 
    480480            $cat_id = $cat_id['term_id']; 
    481481        } 
     
    807807        if ( '' === $slug ) 
    808808            continue; 
    809         if ( !$cat_id = term_exists( $cat_name, 'link_category' ) ) 
    810             $cat_id = wp_insert_term( $cat_name, 'link_category' ); 
    811         if ( is_wp_error( $cat_id ) ) { 
     809 
     810        $cat_id = wp_insert_term( $cat_name, 'link_category' ); 
     811        if ( ! $cat_id || is_wp_error( $cat_id ) ) { 
    812812            continue; 
    813         } elseif ( is_array( $cat_id ) ) { 
     813        } else { 
    814814            $cat_id = $cat_id['term_id']; 
    815815        } 
Note: See TracChangeset for help on using the changeset viewer.