WP_REST_Request::is_json_content_type()publicWP 5.6.0

Checks if the request has specified a JSON Content-Type.

Method of the class: WP_REST_Request{}

No Hooks.

Return

true|false. True if the Content-Type header is JSON.

Usage

$WP_REST_Request = new WP_REST_Request();
$WP_REST_Request->is_json_content_type();

Changelog

Since 5.6.0 Introduced.

WP_REST_Request::is_json_content_type() code WP 6.5.2

public function is_json_content_type() {
	$content_type = $this->get_content_type();

	return isset( $content_type['value'] ) && wp_is_json_media_type( $content_type['value'] );
}