[wp-trac] [WordPress Trac] #29255: wp_insert_term() calls term_exists() with 'slug' where 'slug' gets compared to term 'name'

WordPress Trac noreply at wordpress.org
Sat Jan 17 01:26:22 UTC 2015


#29255: wp_insert_term() calls term_exists() with 'slug' where 'slug' gets compared
to term 'name'
---------------------------------------------+-----------------------------
 Reporter:  Rob Walker                       |       Owner:
     Type:  defect (bug)                     |      Status:  new
 Priority:  normal                           |   Milestone:  Awaiting
Component:  Taxonomy                         |  Review
 Severity:  normal                           |     Version:  3.9.2
 Keywords:  good-first-bug needs-unit-tests  |  Resolution:
                                             |     Focuses:
---------------------------------------------+-----------------------------

Comment (by boonebgorges):

 Thanks for having a look, MikeNGarrett - but I think you're wrong about
 this. The `term_exists()` check is still being run, and if it matches
 based on 'name' alone, then a `WP_Error` will be thrown. In 4.0, see
 https://core.trac.wordpress.org/browser/tags/4.0/src/wp-
 includes/taxonomy.php#L2481, especially line 2500; in 4.1, see
 https://core.trac.wordpress.org/browser/tags/4.1/src/wp-
 includes/taxonomy.php#L2826. In 4.1, we never reach
 `wp_unique_term_slug()` in the case described by Rob Walker.

 [attachment:29255.test.diff] is an attempt to write a unit test that
 describes the bug in as narrow a fashion as possible. It fails on 4.1 and
 4.0.

 The purpose of this section of `wp_insert_term()` is to ensure that in a
 hierarchical taxonomy, terms at the same level of the hierarchy do not
 share the same 'name'. So the `term_exists()` check should probably be
 swapped out with `get_term_by( 'name' )`, though it'll probably need more
 massaging than just this to make it work properly.

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


More information about the wp-trac mailing list