wp_is_json_request()

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


Return Return

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


Top ↑

Source Source

File: wp-includes/load.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;

}


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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