_json_wp_die_handler( string $message, string $title = , string|array $args = array() )

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Kills WordPress execution and displays JSON response with an error message.

Description

This is the handler for wp_die() when processing JSON requests.

Parameters

$messagestringrequired
Error message.
$titlestringoptional
Error title.

Default:''

$argsstring|arrayoptional
Arguments to control behavior.

Default:array()

Source

function _json_wp_die_handler( $message, $title = '', $args = array() ) {
	list( $message, $title, $parsed_args ) = _wp_die_process_input( $message, $title, $args );

	$data = array(
		'code'              => $parsed_args['code'],
		'message'           => $message,
		'data'              => array(
			'status' => $parsed_args['response'],
		),
		'additional_errors' => $parsed_args['additional_errors'],
	);

	if ( isset( $parsed_args['error_data'] ) ) {
		$data['data']['error'] = $parsed_args['error_data'];
	}

	if ( ! headers_sent() ) {
		header( "Content-Type: application/json; charset={$parsed_args['charset']}" );
		if ( null !== $parsed_args['response'] ) {
			status_header( $parsed_args['response'] );
		}
		nocache_headers();
	}

	echo wp_json_encode( $data );
	if ( $parsed_args['exit'] ) {
		die();
	}
}

Changelog

VersionDescription
5.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.