wp_is_json_request() WordPress Function

The wp_is_json_request function is used to check whether a JSON request has been made. This function is useful for checking whether data has been sent to the server in JSON format.

wp_is_json_request() #

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


Return

(bool) True if Accepts or Content-Type headers contain application/json. False otherwise.


Top ↑

Source

File: wp-includes/load.php

function wp_is_json_request() {

	if ( isset( $_SERVER['HTTP_ACCEPT'] ) && wp_is_json_media_type( $_SERVER['HTTP_ACCEPT'] ) ) {
		return true;
	}

	if ( isset( $_SERVER['CONTENT_TYPE'] ) && wp_is_json_media_type( $_SERVER['CONTENT_TYPE'] ) ) {
		return true;
	}

	return false;

}


Top ↑

Changelog

Changelog
VersionDescription
5.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.