Uses
Uses | Description |
---|---|
wp-includes/rest-api/class-wp-rest-server.php: WP_REST_Server::set_status() | Sends an HTTP status code. |
wp-includes/functions.php: wp_json_encode() | Encode a variable into JSON, with some sanity checks. |
Retrieves an appropriate error representation in JSON.
Note: This should only be used in WP_REST_Server::serve_request(), as it cannot handle WP_Error internally. All callbacks and other internal methods should instead return a WP_Error with the data set to an array that includes a ‘status’ key, with the value being the HTTP status to send.
(string) (Required) WP_Error-style code.
(string) (Required) Human-readable message.
(int) (Optional) HTTP status code to send.
Default value: null
(string) JSON representation of the error
File: wp-includes/rest-api/class-wp-rest-server.php
protected function json_error( $code, $message, $status = null ) { if ( $status ) { $this->set_status( $status ); } $error = compact( 'code', 'message' ); return wp_json_encode( $error ); }
Version | Description |
---|---|
4.4.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_server/json_error