<title><?php echo $title; ?></title>
border: 1px solid #ccd0d4;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
border-bottom: 1px solid #dadada;
#error-page .wp-die-message {
font-family: Consolas, Monaco, monospace;
0 0 2px 1px rgba(30, 140, 190, 0.8);
0 0 2px 1px rgba(30, 140, 190, 0.8);
border: 1px solid #016087;
-webkit-border-radius: 3px;
-webkit-appearance: none;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-shadow: 0 0 0 1px #007cba;
box-shadow: 0 0 0 1px #007cba;
outline: 2px solid transparent;
-webkit-box-shadow: none;
if ( 'rtl' === $text_direction ) {
echo 'body { font-family: Tahoma, Arial; }';
<?php endif; // ! did_action( 'admin_head' ) ?>
if ( $parsed_args['exit'] ) {
* Kills WordPress execution and displays Ajax response with an error message.
* This is the handler for wp_die() when processing Ajax requests.
* @param string $message Error message.
* @param string $title Optional. Error title (unused). Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
function _ajax_wp_die_handler( $message, $title = '', $args = array() ) {
// Set default 'response' to 200 for Ajax requests.
array( 'response' => 200 )
list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
if ( ! headers_sent() ) {
// This is intentional. For backward-compatibility, support passing null here.
if ( null !== $args['response'] ) {
status_header( $parsed_args['response'] );
if ( is_scalar( $message ) ) {
$message = (string) $message;
if ( $parsed_args['exit'] ) {
* Kills WordPress execution and displays JSON response with an error message.
* This is the handler for wp_die() when processing JSON requests.
* @param string $message Error message.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
function _json_wp_die_handler( $message, $title = '', $args = array() ) {
list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
'code' => $parsed_args['code'],
'status' => $parsed_args['response'],
'additional_errors' => $parsed_args['additional_errors'],
if ( ! headers_sent() ) {
header( "Content-Type: application/json; charset={$parsed_args['charset']}" );
if ( null !== $parsed_args['response'] ) {
status_header( $parsed_args['response'] );
echo wp_json_encode( $data );
if ( $parsed_args['exit'] ) {
* Kills WordPress execution and displays JSONP response with an error message.
* This is the handler for wp_die() when processing JSONP requests.
* @param string $message Error message.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
function _jsonp_wp_die_handler( $message, $title = '', $args = array() ) {
list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
'code' => $parsed_args['code'],
'status' => $parsed_args['response'],
'additional_errors' => $parsed_args['additional_errors'],
if ( ! headers_sent() ) {
header( "Content-Type: application/javascript; charset={$parsed_args['charset']}" );
header( 'X-Content-Type-Options: nosniff' );
header( 'X-Robots-Tag: noindex' );
if ( null !== $parsed_args['response'] ) {
status_header( $parsed_args['response'] );
$result = wp_json_encode( $data );
$jsonp_callback = $_GET['_jsonp'];
echo '/**/' . $jsonp_callback . '(' . $result . ')';
if ( $parsed_args['exit'] ) {
* Kills WordPress execution and displays XML response with an error message.
* This is the handler for wp_die() when processing XMLRPC requests.
* @global wp_xmlrpc_server $wp_xmlrpc_server
* @param string $message Error message.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
global $wp_xmlrpc_server;
list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
if ( ! headers_sent() ) {
if ( $wp_xmlrpc_server ) {
$error = new IXR_Error( $parsed_args['response'], $message );
$wp_xmlrpc_server->output( $error->getXml() );
if ( $parsed_args['exit'] ) {
* Kills WordPress execution and displays XML response with an error message.
* This is the handler for wp_die() when processing XML requests.
* @param string $message Error message.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
function _xml_wp_die_handler( $message, $title = '', $args = array() ) {
list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
$message = htmlspecialchars( $message );
$title = htmlspecialchars( $title );
<code>{$parsed_args['code']}</code>
<title><![CDATA[{$title}]]></title>
<message><![CDATA[{$message}]]></message>
<status>{$parsed_args['response']}</status>
if ( ! headers_sent() ) {
header( "Content-Type: text/xml; charset={$parsed_args['charset']}" );
if ( null !== $parsed_args['response'] ) {
status_header( $parsed_args['response'] );
if ( $parsed_args['exit'] ) {
* Kills WordPress execution and displays an error message.
* This is the handler for wp_die() when processing APP requests.
* @since 5.1.0 Added the $title and $args parameters.
* @param string $message Optional. Response to print. Default empty.
* @param string $title Optional. Error title (unused). Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
function _scalar_wp_die_handler( $message = '', $title = '', $args = array() ) {
list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );
if ( $parsed_args['exit'] ) {
if ( is_scalar( $message ) ) {
die( (string) $message );
if ( is_scalar( $message ) ) {
* Processes arguments passed to wp_die() consistently for its handlers.
* @param string|WP_Error $message Error message or WP_Error object.
* @param string $title Optional. Error title. Default empty.
* @param string|array $args Optional. Arguments to control behavior. Default empty array.
* @type string $0 Error message.
* @type string $1 Error title.
* @type array $2 Arguments to control behavior.
function _wp_die_process_input( $message, $title = '', $args = array() ) {
'additional_errors' => array(),
$args = wp_parse_args( $args, $defaults );
if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) {
if ( ! empty( $message->errors ) ) {
foreach ( (array) $message->errors as $error_code => $error_messages ) {
foreach ( (array) $error_messages as $error_message ) {
'message' => $error_message,
'data' => $message->get_error_data( $error_code ),
$message = $errors[0]['message'];
if ( empty( $args['code'] ) ) {
$args['code'] = $errors[0]['code'];
if ( empty( $args['response'] ) && is_array( $errors[0]['data'] ) && ! empty( $errors[0]['data']['status'] ) ) {
$args['response'] = $errors[0]['data']['status'];
if ( empty( $title ) && is_array( $errors[0]['data'] ) && ! empty( $errors[0]['data']['title'] ) ) {
$title = $errors[0]['data']['title'];
$args['additional_errors'] = array_values( $errors );
$have_gettext = function_exists( '__' );
// The $title and these specific $args must always have a non-empty value.
if ( empty( $args['code'] ) ) {
$args['code'] = 'wp_die';
if ( empty( $args['response'] ) ) {
$title = $have_gettext ? __( 'WordPress › Error' ) : 'WordPress › Error';
if ( empty( $args['text_direction'] ) || ! in_array( $args['text_direction'], array( 'ltr', 'rtl' ), true ) ) {
$args['text_direction'] = 'ltr';
if ( function_exists( 'is_rtl' ) && is_rtl() ) {
$args['text_direction'] = 'rtl';
if ( ! empty( $args['charset'] ) ) {
$args['charset'] = _canonical_charset( $args['charset'] );
return array( $message, $title, $args );
* Encode a variable into JSON, with some sanity checks.
* @since 5.3.0 No longer handles support for PHP < 5.6.
* @param mixed $data Variable (usually an array or object) to encode as JSON.
* @param int $options Optional. Options to be passed to json_encode(). Default 0.
* @param int $depth Optional. Maximum depth to walk through $data. Must be
* greater than 0. Default 512.
* @return string|false The JSON encoded string, or false if it cannot be encoded.
function wp_json_encode( $data, $options = 0, $depth = 512 ) {
$json = json_encode( $data, $options, $depth );
// If json_encode() was successful, no need to do more sanity checking.
$data = _wp_json_sanity_check( $data, $depth );
} catch ( Exception $e ) {
return json_encode( $data, $options, $depth );
* Perform sanity checks on data that shall be encoded to JSON.
* @throws Exception If depth limit is reached.
* @param mixed $data Variable (usually an array or object) to encode as JSON.
* @param int $depth Maximum depth to walk through $data. Must be greater than 0.
* @return mixed The sanitized data that shall be encoded to JSON.
function _wp_json_sanity_check( $data, $depth ) {
throw new Exception( 'Reached depth limit' );
if ( is_array( $data ) ) {
foreach ( $data as $id => $el ) {
// Don't forget to sanitize the ID!
if ( is_string( $id ) ) {
$clean_id = _wp_json_convert_string( $id );