[wp-trac] [WordPress Trac] #40206: wp_insert_term() $slug_provided check fails

WordPress Trac noreply at wordpress.org
Mon Mar 20 11:56:27 UTC 2017


#40206: wp_insert_term() $slug_provided check fails
--------------------------+-----------------------------
 Reporter:  esemlabel     |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  4.7.3
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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
 <?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.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40206>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list