[wp-trac] [WordPress Trac] #30780: Inconsistent behavior/results of wp_insert_term and wp_update_term

WordPress Trac noreply at wordpress.org
Fri Dec 19 14:42:54 UTC 2014


#30780: Inconsistent behavior/results of wp_insert_term and wp_update_term
-------------------------+------------------
 Reporter:  ipm-frommen  |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  4.2
Component:  Taxonomy     |     Version:  4.1
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+------------------
Changes (by boonebgorges):

 * type:  defect (bug) => enhancement
 * milestone:  Awaiting Review => 4.2


Comment:

 ipm-frommen - Thanks for the report.

 >  This means, I have two terms (one DB entry each) that have the same
 slug, each in one of the two mentioned taxonomies.

 The ability to create terms with duplicate slugs in separate taxonomies is
 new to WP 4.1. See #21950 [30240]. Due to an oversight, the ability to
 have terms with duplicate slugs was not extended to term *updating*. So
 you're correct that this inconsistency is not by design.

 Your patch is a good start, but it's not narrow enough - the checks that
 are required when updating a term are somewhat different than what is
 required when creating a term. We have to account specifically for the
 case where WP changes term slugs in response to a term parent being
 changed (for legacy reasons - you might argue that this is a bug). In
 [attachment:30780.2.patch], I've broken out the 'slug' checks from the
 'name' checks, because the requirements are different in each case, and
 `term_exists()` muddies the waters. With the patch, the constraints look
 like this:

 - Duplicate 'slug' enforcement is performed by `wp_unique_term_slug()`.
 This mirrors `wp_insert_term()`. The one exception is, as noted above,
 that updating a term to a new parent that already has a child with the
 same slug will result in an updated term with a slug that's been appended
 with the parent slug.
 - Duplicate 'name' is allowed in all cases, except for term that exist at
 the same hierarchy level of the same taxonomy.

 I've also included new unit tests and modified the existing ones as
 necessary to describe the desired behavior.

 ipm-frommen, would you mind having a look? Apply the patch locally and see
 if the behavior with term updates is what you'd expect.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30780#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list