Make WordPress Core

Opened 7 years ago

Last modified 12 months ago

#40206 new defect (bug)

wp_insert_term() $slug_provided check fails

Reported by: esemlabel's profile esemlabel Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.3
Component: Taxonomy Keywords: has-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 (6)

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

4 years ago

#2 @markparnell
4 years ago

  • Component changed from General to Taxonomy

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

#3 @markparnell
4 years ago

  • Keywords needs-patch added

This ticket was mentioned in PR #4486 on WordPress/wordpress-develop by @albatross10.

12 months ago

  • Keywords has-patch added; needs-patch removed

It allows a term to be added even if a term with slug and "2" appended is present already. Otherwise the consecutive term would check for the slug-2 and see that it is present and you need to manually add the slug.

Trac ticket:

#5 @albatross10
12 months ago

Hello @markparnell

I traced back to this Ticket where the change was added. Do we still want to proceed with this?

#6 @albatross10
12 months ago

I also tested the case present in the

I added $$$$ and continued to add it. And this adds the term ID as slug. So the check present prevents $$$$ from adding again. If we proceed with removing that line and do this:

if ( $name_match->slug === $slug || $slug_match ) {

It continues to add it.

Note: See TracTickets for help on using tickets.