From 675de40f118573c45036a42b2db557aa29f46e76 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Wed, 17 Jun 2015 23:12:08 +0000 Subject: [PATCH] Press This: show error message when the user is attempting to add a category that already exists. Fixes #32339. git-svn-id: https://develop.svn.wordpress.org/trunk@32827 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-press-this.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/includes/class-wp-press-this.php b/src/wp-admin/includes/class-wp-press-this.php index 0ed6d5f444..51b5104e32 100644 --- a/src/wp-admin/includes/class-wp-press-this.php +++ b/src/wp-admin/includes/class-wp-press-this.php @@ -201,11 +201,17 @@ class WP_Press_This { continue; } - // @todo Find a more performant to check existence, maybe get_term() with a separate parent check. - if ( ! $cat_id = term_exists( $cat_name, $taxonomy->name, $parent ) ) { - $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); + // @todo Find a more performant way to check existence, maybe get_term() with a separate parent check. + if ( term_exists( $cat_name, $taxonomy->name, $parent ) ) { + if ( count( $names ) === 1 ) { + wp_send_json_error( array( 'errorMessage' => __( 'This category already exists.' ) ) ); + } else { + continue; + } } + $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); + if ( is_wp_error( $cat_id ) ) { continue; } elseif ( is_array( $cat_id ) ) {