#44983 closed defect (bug) (fixed)
REST API: Undefined-property notice when setting term parent to 0
| Reported by: | dlh | Owned by: | SergeyBiryukov |
|---|---|---|---|
| Priority: | normal | Milestone: | 5.2 |
| Component: | REST API | Version: | 4.7 |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Attempting to create or update a term with a parent of 0 using the REST API generates a undefined-property notice because a WP_Error object is treated as a WP_Term.
The WP_Error comes from calling get_term( 0 ), and the terms controller checks for only a truthy response before attempting to access the term_id property.
The attached patch includes tests demonstrating the issue, adds verification that the response from get_term() is a term, and, as a tiny optimization, skips the get_term() check when the provided parent is 0.
Attachments (2)
Change History (14)
#6
@
8 years ago
Yeah, it's funny-looking. The only reason it's there is so that the logic in that condition would be isolated from a change in the initialization, should that ever happen. No big deal to me either way, though.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
@dlh One small thing I noticed in the patch.
This part is redundant, because
$parent_term_idis already initialized as0right above this on line 672.