Make WordPress Core

Opened 5 years ago

Last modified 20 months 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: Taxonomy Keywords: needs-patch
Focuses: Cc:


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.

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 (3)

This ticket was mentioned in Slack in #core by noisysocks. View the logs.

20 months ago

#2 @markparnell
20 months ago

  • Component changed from General to Taxonomy

Agreed - I can't see the need for the ! $slug_provided check there.

#3 @markparnell
20 months ago

  • Keywords needs-patch added
Note: See TracTickets for help on using tickets.