Opened 19 years ago
Closed 19 years ago
#5226 closed defect (bug) (fixed)
Potential fatal object type mismatch in wp_set_object_terms()
| Reported by: | tellyworth | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 2.5 |
| Component: | General | Version: | 2.3 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
Description
The wp_set_object_terms() function calls wp_insert_term() and then immediately assumes the return result is an array, around line 1121:
if ( !$id = is_term($term, $taxonomy) ) $id = wp_insert_term($term, $taxonomy); $term_ids[] = $id['term_id'];
But wp_insert_term() doesn't always return an array, it can return a WP_Error object. This causes a fatal error:
PHP Fatal error: Cannot use object of type WP_Error as array in wordpress/wp-includes/taxonomy.php on line 1122
This turned up while I was writing unit tests. I'm not quite sure what the cause is yet because I can't backtrace a fatal error. It might not happen in normal operation, but I don't think a blind assumption like that is safe considering the consequences.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Found the trigger - my fault, a filter gone bad that was causing a NULL category name. Nevertheless, I think the code still needs an error check.