[wp-trac] [WordPress Trac] #44983: REST API: Undefined-property notice when setting term parent to 0

WordPress Trac noreply at wordpress.org
Sat Sep 22 18:21:41 UTC 2018


#44983: REST API: Undefined-property notice when setting term parent to 0
--------------------------+--------------------------------------
 Reporter:  dlh           |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  4.7
 Severity:  normal        |   Keywords:  has-patch has-unit-tests
  Focuses:                |
--------------------------+--------------------------------------
 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`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44983>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list