Skip to content

Instantly share code, notes, and snippets.

@wpsmith wpsmith/is_rest.php
Last active Jun 4, 2019

Embed
What would you like to do?
PHP: Determines whether the request is a WordPress API request.
<?php
/**
* Determines whether the current request is a RESTful request.
*
* @return bool
*/
function is_rest() {
return (
( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
( isset( $GLOBALS['wp'] ) && ! empty( $GLOBALS['wp']->query_vars['rest_route'] ) )
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.