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.
Built from https://develop.svn.wordpress.org/trunk@39637


git-svn-id: http://core.svn.wordpress.org/trunk@39577 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2016-12-23 03:11:40 +00:00
parent af885f45cf
commit a3ea7ea2e9
2 changed files with 9 additions and 9 deletions

View File

@ -472,11 +472,11 @@ function _wp_ajax_add_hierarchical_term() {
$category_nicename = sanitize_title($cat_name); $category_nicename = sanitize_title($cat_name);
if ( '' === $category_nicename ) if ( '' === $category_nicename )
continue; continue;
if ( !$cat_id = term_exists( $cat_name, $taxonomy->name, $parent ) )
$cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) );
if ( is_wp_error( $cat_id ) ) { if ( ! $cat_id || is_wp_error( $cat_id ) ) {
continue; continue;
} elseif ( is_array( $cat_id ) ) { } else {
$cat_id = $cat_id['term_id']; $cat_id = $cat_id['term_id'];
} }
$checked_categories[] = $cat_id; $checked_categories[] = $cat_id;
@ -806,11 +806,11 @@ function wp_ajax_add_link_category( $action ) {
$slug = sanitize_title($cat_name); $slug = sanitize_title($cat_name);
if ( '' === $slug ) if ( '' === $slug )
continue; continue;
if ( !$cat_id = term_exists( $cat_name, 'link_category' ) )
$cat_id = wp_insert_term( $cat_name, 'link_category' ); $cat_id = wp_insert_term( $cat_name, 'link_category' );
if ( is_wp_error( $cat_id ) ) { if ( ! $cat_id || is_wp_error( $cat_id ) ) {
continue; continue;
} elseif ( is_array( $cat_id ) ) { } else {
$cat_id = $cat_id['term_id']; $cat_id = $cat_id['term_id'];
} }
$cat_name = esc_html( $cat_name ); $cat_name = esc_html( $cat_name );

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.8-alpha-39636'; $wp_version = '4.8-alpha-39637';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.