WC_API_Server::is_json_request()
Check if the current request accepts a JSON response by checking the endpoint suffix (.json) or the HTTP ACCEPT header
Method of the class: WC_API_Server{}
No Hooks.
Return
true|false
.
Usage
// private - for code of main (parent) class only $result = $this->is_json_request();
Changelog
Since 2.1 | Introduced. |
WC_API_Server::is_json_request() WC API Server::is json request code WC 7.7.0
private function is_json_request() { // check path if ( false !== stripos( $this->path, '.json' ) ) { return true; } // check ACCEPT header, only 'application/json' is acceptable, see RFC 4627 if ( isset( $this->headers['ACCEPT'] ) && 'application/json' == $this->headers['ACCEPT'] ) { return true; } return false; }