Fatal error in Endpoint_Api::save_cache() method
-
Hi there,
We are experiencing fatal errors for unauthorized requests to WooCommerce endpoints. We tracked the issue down to the
Endpoint_Api::save_cache()method.public function save_cache( $result, \WP_REST_Server $server, \WP_REST_Request $request ) { if ( ! empty( $result ) && is_array( $result ) && isset( $result['data']['status'] ) && 200 !== (int) $result['data']['status'] ) { return $result; } ... }Turns out
$result['data']is not guaranteed to be an Array and this will result in a fatal error:PHP Fatal error: Uncaught Error: Cannot use object of type stdClass as array in .../wp-content/plugins/wp-rest-cache/includes/api/class-endpoint-api.php:232It might be due to the fact WC is returning
WP_Errorobjects in their permission handlers but this should be further investigated.However, to more reliably retrieve the actual HTTP status code of the ongoing response you should use the
http_response_code()php function. By the timerest_pre_serve_requestfilter is run that header is already set byWP_REST_Server::serve_request()method.Let us know if you need more information on the matter.
The topic ‘Fatal error in Endpoint_Api::save_cache() method’ is closed to new replies.