WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/17/2015 11:12:08 PM (7 years ago)
Author:
azaozz
Message:

Press This: show error message when the user is attempting to add a category that already exists.
Fixes #32339.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-press-this.php

    r32800 r32827  
    202202            }
    203203
    204             // @todo Find a more performant to check existence, maybe get_term() with a separate parent check.
    205             if ( ! $cat_id = term_exists( $cat_name, $taxonomy->name, $parent ) ) {
    206                 $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) );
    207             }
     204            // @todo Find a more performant way to check existence, maybe get_term() with a separate parent check.
     205            if ( term_exists( $cat_name, $taxonomy->name, $parent ) ) {
     206                if ( count( $names ) === 1 ) {
     207                    wp_send_json_error( array( 'errorMessage' => __( 'This category already exists.' ) ) );
     208                } else {
     209                    continue;
     210                }
     211            }
     212
     213            $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) );
    208214
    209215            if ( is_wp_error( $cat_id ) ) {
Note: See TracChangeset for help on using the changeset viewer.