#44983 closed defect (bug) (fixed)
REST API: Undefined-property notice when setting term parent to 0
Reported by: | dlh | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.2 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
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)
#1
@
6 years ago
- Milestone changed from Awaiting Review to 4.9.9
- Owner set to SergeyBiryukov
- Status changed from new to reviewing
#6
@
6 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.
#7
@
6 years ago
- Milestone changed from 5.0.3 to 5.1
Since this is only a notice, let's bump it to 5.1.
@dlh One small thing I noticed in the patch.
This part is redundant, because
$parent_term_id
is already initialized as0
right above this on line 672.