WordPress.org

Make WordPress Core

Opened 3 years ago

#40206 new defect (bug)

wp_insert_term() $slug_provided check fails

Reported by: esemlabel Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.3
Component: General Keywords:
Focuses: Cc:

Description

Imagine 2 city terms with same name, whereas state is stored inside its term_meta.
"Washington, Connecticut"
"Washington, Georgia"
So you have 2 identical names, but technically different terms with appropriate content.

If one of this city is already saved with slug "washington-2", than you will not able to save the second without manually set slug value to "washington".

The problem is in wp_insert_term() func.
https://core.trac.wordpress.org/browser/trunk/src/wp-includes/taxonomy.php#L2018

<?php
if ( $name_match ) {
    $slug_match = get_term_by( 'slug', $slug, $taxonomy );
    if ( ! $slug_provided || $name_match->slug === $slug || $slug_match ) {
        // return new WP_Error
    }
}

As result, $name_match->slug !== $slug && ! $slug_match, but $slug_provided weren't provided, so it return WP_Error, instead of save new term "Washington" with slug "washington".

I think the last 2 of 3 checks is enough and ! $slug_provided shouldn't exits here.

Change History (0)

Note: See TracTickets for help on using tickets.