WP_REST_Server::json_error( string $code, string $message, int|null $status = null ): string
- Since
- 4.4.0
- Source
wp-includes/rest-api/class-wp-rest-server.php:232
Retrieves an appropriate error representation in JSON.
Description
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.
Parameters
$codestring- WP_Error-style code.
$messagestring- Human-readable message.
$statusint|nulloptional- HTTP status code to send. Default null.Default:
null
Return
string- JSON representation of the error.
Uses · 2
- wp_json_encode()Encodes a variable into JSON, with some confidence checks.
- WP_REST_Server::set_status()Sends an HTTP status code.
Used by · 1
- WP_REST_Server::serve_request()Handles serving a REST API request.
Source
protected function json_error( $code, $message, $status = null ) { if ( $status ) { $this->set_status( $status ); } $error = compact( 'code', 'message' ); return wp_json_encode( $error ); }History
Introduced in 4.4.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
6.9.7
Parameter
$status retyped from int to int|null.verified against source4.4.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/rest-api/class-wp-rest-server.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.