From 35ccbc8368388ed7406bd93636595417b2d940cc Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 23 Dec 2016 03:10:36 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@39637 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ajax-actions.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 660d3739f4..e740c93a1c 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -472,11 +472,11 @@ function _wp_ajax_add_hierarchical_term() { $category_nicename = sanitize_title($cat_name); if ( '' === $category_nicename ) continue; - if ( !$cat_id = term_exists( $cat_name, $taxonomy->name, $parent ) ) - $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); - if ( is_wp_error( $cat_id ) ) { + + $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); + if ( ! $cat_id || is_wp_error( $cat_id ) ) { continue; - } elseif ( is_array( $cat_id ) ) { + } else { $cat_id = $cat_id['term_id']; } $checked_categories[] = $cat_id; @@ -806,11 +806,11 @@ function wp_ajax_add_link_category( $action ) { $slug = sanitize_title($cat_name); if ( '' === $slug ) continue; - if ( !$cat_id = term_exists( $cat_name, 'link_category' ) ) - $cat_id = wp_insert_term( $cat_name, 'link_category' ); - if ( is_wp_error( $cat_id ) ) { + + $cat_id = wp_insert_term( $cat_name, 'link_category' ); + if ( ! $cat_id || is_wp_error( $cat_id ) ) { continue; - } elseif ( is_array( $cat_id ) ) { + } else { $cat_id = $cat_id['term_id']; } $cat_name = esc_html( $cat_name );