Opened 7 years ago
Last modified 16 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: | has-patch |
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 (6)
This ticket was mentioned in Slack in #core by noisysocks. View the logs.
4 years ago
This ticket was mentioned in PR #4486 on WordPress/wordpress-develop by @albatross10.
16 months ago
#4
- 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: https://core.trac.wordpress.org/ticket/40206
#5
@
16 months ago
Hello @markparnell
I traced back to this Ticket https://core.trac.wordpress.org/ticket/39984 where the change was added. Do we still want to proceed with this?
#6
@
16 months ago
I also tested the case present in the https://core.trac.wordpress.org/ticket/39984
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.
Agreed - I can't see the need for the
! $slug_provided
check there.