[wp-trac] [WordPress Trac] #34413: calling register_taxonomy() multiple times will overwrite existing object types

WordPress Trac noreply at wordpress.org
Sat Oct 24 02:04:05 UTC 2015


#34413: calling register_taxonomy() multiple times will overwrite existing object
types
--------------------------+---------------------------
 Reporter:  BjornW        |       Owner:  drewapicture
     Type:  defect (bug)  |      Status:  reviewing
 Priority:  normal        |   Milestone:  4.4
Component:  Taxonomy      |     Version:  2.6
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  docs
--------------------------+---------------------------
Changes (by boonebgorges):

 * keywords:  has-patch has-unit-tests commit => has-patch


Comment:

 [attachment:34413.3.diff] seems wrong to me. Either we should (a) bail out
 of `register_taxonomy( 'foo' )` with an error if `foo` is already
 registered (so the first call to `register_taxonomy()` wins), or (b) we
 should overwrite the entire taxonomy each time (so the last one wins).
 Treating `object_type` differently from every other parameter is a recipe
 for confusion.

 Even if we were going to allow subsequent calls to `register_taxonomy()`
 to update existing taxonomies, merging the object types doesn't seem
 right. Say I originally registered the taxonomy with object type 'post'
 and I want to change it to 'page' (only). The naive syntax (on the current
 proposal) would be to say `register_taxonomy( 'foo', 'page' )`. But with
 [attachment:34413.3.diff] , there's no way to do this.

 If you want to add additional object types to an existing taxonomy, use
 `register_taxonomy_for_object_type()`.

 > I think the current docs are somewhat accurate, overwriting a previously
 registered taxonomy counts as modifying.

 This seems like the crux of the problem: you can think of it this way, but
 it's not technically the case. I think we should make the docs clearer
 that what really happens here is an overwrite [attachment:add-extra-info-
 to-register-taxonomy-comment.diff]. (

 If we want a function for updating taxonomies, that's fine, but it should
 be a separate function, maybe one that wraps `register_taxonomy()`. See
 `wp_update_post()`.

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


More information about the wp-trac mailing list