#29899 closed enhancement (wontfix)
wp_insert_term should return an object instead of an array
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 2.3 |
| Component: | Taxonomy | Keywords: | |
| Focuses: | Cc: |
Description
When using wp_insert_term() I believe the return value should be an object like get_term() and get_term_by()
The rationale behind this can be summarized in this code snippet:
$term = get_term_by('name', 'my-term', 'my-taxonomy');
if($term) {
$term_id = $term->term_id;
} else {
$term = wp_insert_term('my-term', 'my-taxonomy');
$term_id = $term['term_id'];
}
If wp_insert_term() returned an object that code could be simplified to:
$term = get_term_by('name', 'my-term', 'my-taxonomy');
if(!$term) {
$term = wp_insert_term('my-term', 'my-taxonomy');
}
$term_id = $term->term_id;
Change History (2)
Note: See
TracTickets for help on using
tickets.
Thanks for the bug report!
I understand where you're coming from, but I don't think this is a viable change. Naturally, we can't change the default behaviour, so the only other option is add an extra
$outputparameter. Plugins wanting to use this new parameter would still need to maintain backwards compatibility for old versions of WordPress, which would increase their code complexity.