Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Last active June 4, 2019 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpsmith/8ca175ed362e78b4e7761907a5cac1b9 to your computer and use it in GitHub Desktop.
Save wpsmith/8ca175ed362e78b4e7761907a5cac1b9 to your computer and use it in GitHub Desktop.
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