Make WordPress Core


Ignore:
Timestamp:
03/03/2017 02:39:09 AM (8 years ago)
Author:
boonebgorges
Message:

Taxonomy: Improve precision of duplicate name checks when inserting terms.

wp_insert_term() does not allow for terms with the same name to exist
at the same hierarchy level, unless the second term has a unique slug.
When this logic was refactored in [31792] and [34809], a bug was
introduced whereby it was possible to bypass the no-same-named-sibling
check in cases where the first term had a non-auto-generated slug
(ie, where the name was 'Foo' but the slug something other than 'foo',
such that the second term would get the non-matching slug 'foo').

This changeset fixes this issue by ensuring that the duplicate name
check runs both in cases where there's an actual slug clash *and* in
cases where no explicit slug has been provided to wp_insert_term().
The result is a more reliable error condition:
wp_insert_term( 'Foo' ... ) will always fail if there's a sibling
'Foo', regardless of the sibling's slug.

Props mikejolley.
See #39984.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r40143 r40144  
    20642064
    20652065                $existing_term = null;
    2066                 if ( $name_match->slug === $slug && in_array( $name, wp_list_pluck( $siblings, 'name' ) ) ) {
     2066                if ( ( ! $slug_provided || $name_match->slug === $slug ) && in_array( $name, wp_list_pluck( $siblings, 'name' ) ) ) {
    20672067                    $existing_term = $name_match;
    20682068                } elseif ( $slug_match && in_array( $slug, wp_list_pluck( $siblings, 'slug' ) ) ) {
Note: See TracChangeset for help on using the changeset viewer.