What is the best way to check whether a request is an API request?
Note that the request might be a custom API request, which means it may be as follows:
mysite.com/wp-json/my_namespace/my_version/my_action
Obviously, I can check whether the API route wp-json, but there should be a built-in function to check that.
I need it to do some hooks such as
add_action('init', 'do_something_only_if_api_request');
function do_something_only_if_api_request()
{
if ( ! wp_api_request() ) {
return;
}
// do stuff
}