[wp-trac] [WordPress Trac] #40580: rest_ensure_response() can return WP_Error object, but is consequently not checked in get_item() method

WordPress Trac noreply at wordpress.org
Wed Apr 26 15:46:27 UTC 2017


#40580: rest_ensure_response() can return WP_Error object, but is consequently not
checked in get_item() method
--------------------------+-----------------------------
 Reporter:  ruud@…        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  4.7
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hi,

 I have used the rest_prepare_{$this->post_type} filter to check if my
 single post item is allowed to generate output on a particular REST
 request.
 If in my case this isn't allowed, I use this filter to return a WP_Error
 object

 I was assuming this was OK to do, since also the doc-block says:
 @return WP_REST_Response|WP_Error Response object on success, or WP_Error
 object on failure.

 But.. if $response becomes a WP_Error object, the call to
 $response->link_header fails.

 I will attach a patch to check for the possibility that $response is an
 WP_Error object

 Like to hear your thoughts.

 Thanks,
 Ruud

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


More information about the wp-trac mailing list