Skip to content

Commit 8a44a58

Browse files
2 parents 8b9b1cc + e399671 commit 8a44a58

File tree

5 files changed

+57
-4
lines changed

5 files changed

+57
-4
lines changed

src/wp-admin/edit-tag-form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
<?php } ?>
147147
<?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
148148
<tr class="form-field term-parent-wrap">
149-
<th scope="row"><label for="parent"><?php _ex( 'Parent', 'term parent' ); ?></label></th>
149+
<th scope="row"><label for="parent"><?php echo esc_html( $tax->labels->parent_item ); ?></label></th>
150150
<td>
151151
<?php
152152
$dropdown_args = array(

src/wp-admin/edit-tags.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@
399399
<?php endif; // global_terms_enabled() ?>
400400
<?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
401401
<div class="form-field term-parent-wrap">
402-
<label for="parent"><?php _ex( 'Parent', 'term parent' ); ?></label>
402+
<label for="parent"><?php echo esc_html( $tax->labels->parent_item ); ?></label>
403403
<?php
404404
$dropdown_args = array(
405405
'hide_empty' => 0,

src/wp-includes/class-wp-term-query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public function get_terms() {
323323
*/
324324
do_action( 'pre_get_terms', $this );
325325

326-
$taxonomies = $args['taxonomy'];
326+
$taxonomies = (array) $args['taxonomy'];
327327

328328
// Save queries by not crawling the tree in the case of multiple taxes or a flat tax.
329329
$has_hierarchical_tax = false;

src/wp-includes/taxonomy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,7 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
20402040
$name_matches = get_terms( $taxonomy, array(
20412041
'name' => $name,
20422042
'hide_empty' => false,
2043+
'parent' => $args['parent'],
20432044
) );
20442045

20452046
/*
@@ -2063,7 +2064,7 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
20632064
$siblings = get_terms( $taxonomy, array( 'get' => 'all', 'parent' => $parent ) );
20642065

20652066
$existing_term = null;
2066-
if ( $name_match->slug === $slug && in_array( $name, wp_list_pluck( $siblings, 'name' ) ) ) {
2067+
if ( ( ! $slug_provided || $name_match->slug === $slug ) && in_array( $name, wp_list_pluck( $siblings, 'name' ) ) ) {
20672068
$existing_term = $name_match;
20682069
} elseif ( $slug_match && in_array( $slug, wp_list_pluck( $siblings, 'slug' ) ) ) {
20692070
$existing_term = $slug_match;

tests/phpunit/tests/term/wpInsertTerm.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,58 @@ public function test_wp_insert_term_should_allow_duplicate_names_when_slug_is_a_
376376
$this->assertSame( 'Foo', $t4_term->name );
377377
}
378378

379+
/**
380+
* @ticket 39984
381+
*/
382+
public function test_duplicate_name_check_should_fail_when_no_slug_is_provided_even_when_slugs_would_not_clash() {
383+
register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
384+
$t1 = self::factory()->term->create( array(
385+
'name' => 'Foo',
386+
'slug' => 'foo-no-conflict',
387+
'taxonomy' => 'wptests_tax',
388+
) );
389+
390+
$error = wp_insert_term( 'Foo', 'wptests_tax' );
391+
392+
$this->assertWPError( $error );
393+
$this->assertSame( 'term_exists', $error->get_error_code() );
394+
$this->assertSame( $t1, $error->get_error_data() );
395+
}
396+
397+
/**
398+
* @ticket 39984
399+
*/
400+
public function test_error_should_reference_correct_term_when_rejected_as_duplicate() {
401+
register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
402+
$t1 = self::factory()->term->create( array(
403+
'name' => 'Foo',
404+
'slug' => 'foo',
405+
'taxonomy' => 'wptests_tax',
406+
) );
407+
408+
$t2 = self::factory()->term->create( array(
409+
'name' => 'Bar',
410+
'slug' => 'bar',
411+
'taxonomy' => 'wptests_tax',
412+
) );
413+
414+
$t1_child = wp_insert_term( 'Child', 'wptests_tax', array(
415+
'parent' => $t1,
416+
) );
417+
418+
$t2_child = wp_insert_term( 'Child', 'wptests_tax', array(
419+
'parent' => $t2,
420+
) );
421+
422+
$error = wp_insert_term( 'Child', 'wptests_tax', array(
423+
'parent' => $t2,
424+
) );
425+
426+
$this->assertWPError( $error );
427+
$this->assertSame( 'term_exists', $error->get_error_code() );
428+
$this->assertSame( $t2_child['term_id'], $error->get_error_data() );
429+
}
430+
379431
/**
380432
* @ticket 31328
381433
*/

0 commit comments

Comments
 (0)