wppaste
WordPress

WP_REST_Server::json_error( string $code, string $message, int $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.
$statusintoptional
HTTP status code to send. Default null.Default: null

Return

string
JSON representation of the error

Uses · 2

Used by · 1

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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 source
4.4.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 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.