diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php
index 778a6a3947..c5a3c4d926 100644
|
a
|
b
|
function wp_insert_term( $term, $taxonomy, $args = array() ) { |
| 2523 | 2523 | } |
| 2524 | 2524 | |
| 2525 | 2525 | if ( $name_match ) { |
| 2526 | | $slug_match = get_term_by( 'slug', $slug, $taxonomy ); |
| 2527 | | if ( ! $slug_provided || $name_match->slug === $slug || $slug_match ) { |
| 2528 | | if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
| 2529 | | $siblings = get_terms( |
| 2530 | | array( |
| 2531 | | 'taxonomy' => $taxonomy, |
| 2532 | | 'get' => 'all', |
| 2533 | | 'parent' => $parent, |
| 2534 | | 'update_term_meta_cache' => false, |
| 2535 | | ) |
| 2536 | | ); |
| 2537 | | |
| 2538 | | $existing_term = null; |
| 2539 | | $sibling_names = wp_list_pluck( $siblings, 'name' ); |
| 2540 | | $sibling_slugs = wp_list_pluck( $siblings, 'slug' ); |
| 2541 | | |
| 2542 | | if ( ( ! $slug_provided || $name_match->slug === $slug ) && in_array( $name, $sibling_names, true ) ) { |
| 2543 | | $existing_term = $name_match; |
| 2544 | | } elseif ( $slug_match && in_array( $slug, $sibling_slugs, true ) ) { |
| 2545 | | $existing_term = $slug_match; |
| 2546 | | } |
| | 2526 | if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
| | 2527 | $siblings = get_terms( |
| | 2528 | array( |
| | 2529 | 'taxonomy' => $taxonomy, |
| | 2530 | 'get' => 'all', |
| | 2531 | 'parent' => $parent, |
| | 2532 | 'update_term_meta_cache' => false, |
| | 2533 | ) |
| | 2534 | ); |
| 2547 | 2535 | |
| 2548 | | if ( $existing_term ) { |
| 2549 | | return new WP_Error( 'term_exists', __( 'A term with the name provided already exists with this parent.' ), $existing_term->term_id ); |
| 2550 | | } |
| 2551 | | } else { |
| 2552 | | return new WP_Error( 'term_exists', __( 'A term with the name provided already exists in this taxonomy.' ), $name_match->term_id ); |
| | 2536 | $sibling_names = wp_list_pluck( $siblings, 'name' ); |
| | 2537 | |
| | 2538 | if ( in_array( $name, $sibling_names, true ) ) { |
| | 2539 | return new WP_Error( 'term_exists', __( 'A term with the name provided already exists with this parent.' ), $existing_term->term_id ); |
| 2553 | 2540 | } |
| | 2541 | } else { |
| | 2542 | return new WP_Error( 'term_exists', __( 'A term with the name provided already exists in this taxonomy.' ), $name_match->term_id ); |
| 2554 | 2543 | } |
| 2555 | 2544 | } |
| 2556 | 2545 | |