WordPress at a glance

wp_is_json_request() WP 1.0

Checks whether current request is a JSON request, or is expecting a JSON response.

✈ 1 time = 0.000001s = speed of light | 50000 times = 0.02s = speed of light | PHP 7.2.5, WP 5.0

No Hooks.

Return

true/false. True if Accepts or Content-Type headers contain application/json, false otherwise.

Usage

wp_is_json_request();

Changelog

Since 5.0.0 Introduced.

Code of wp is json request: wp-includes/load.php WP 5.2.3

<?php
function wp_is_json_request() {

	if ( isset( $_SERVER['HTTP_ACCEPT'] ) && false !== strpos( $_SERVER['HTTP_ACCEPT'], 'application/json' ) ) {
		return true;
	}

	if ( isset( $_SERVER['CONTENT_TYPE'] ) && 'application/json' === $_SERVER['CONTENT_TYPE'] ) {
		return true;
	}

	return false;

}
No comments
    Hello, !     Log In . Register