WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 3 years ago

#29852 new enhancement

wp_update_term() should use wp_insert_term() internally

Reported by: boonebgorges Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.3
Component: Taxonomy Keywords: needs-patch
Focuses: Cc:

Description

wp_update_term() and wp_insert_term() have a large amount of overlapping functionality. Things like argument sanitization, term_exists() checks, parent and alias_of validation, and even some hook names are shared between the two. Having the logic separate means twice the unit tests and twice the bug fixes for shared functionality. (See #29848 for an example.) This, in turn, has the potential to hold up future refactoring (#5809).

As much as possible, the duplicate logic should be pulled out of wp_update_term(). Update-specific validation should take place there, and then call wp_insert_term() with a term_id or term_taxonomy_id param. (Suggestions for syntax are welcome.) In wp_insert_term(), break out the logic specific to the creation of new terms, and only run it when no existing term ID is passed to the function. Then, choose whether to run $wpdb->update() or $wpdb->insert() as appropriate.

Change History (2)

#1 follow-up: @chriscct7
3 years ago

  • Priority changed from low to normal

@boonebgorges want to tackle this?

#2 in reply to: ↑ 1 @boonebgorges
3 years ago

Replying to chriscct7:

@boonebgorges want to tackle this?

Yes. It might make sense to do this at the same time that we begin to introduce CRUD functionality to WP_Term.

Note: See TracTickets for help on using tickets.