ACF_Ajax::send_errorpublicACF 5.8.8

Sends a JSON response for the given WP_Error object.

Method of the class: ACF_Ajax{}

No Hooks.

Returns

null. Nothing (null).

Usage

$ACF_Ajax = new ACF_Ajax();
$ACF_Ajax->send_error( $error );
$error(required)
.

Changelog

Since 5.8.8 Introduced.

ACF_Ajax::send_error() code ACF 6.0.4

function send_error( $error ) {

	// Get error status
	$error_data = $error->get_error_data();
	if ( is_array( $error_data ) && isset( $error_data['status'] ) ) {
		$status_code = $error_data['status'];
	} else {
		$status_code = 500;
	}

	wp_send_json(
		array(
			'code'    => $error->get_error_code(),
			'message' => $error->get_error_message(),
			'data'    => $error->get_error_data(),
		),
		$status_code
	);
}