Skip to content

Instantly share code, notes, and snippets.

@robskidmore
Created December 30, 2017 20:26
Show Gist options
  • Save robskidmore/d43ee3a4e53652efb2c3d9e2a0d01b61 to your computer and use it in GitHub Desktop.
Save robskidmore/d43ee3a4e53652efb2c3d9e2a0d01b61 to your computer and use it in GitHub Desktop.
function isRestUrl() {
$bIsRest = false;
if ( function_exists( 'rest_url' ) && !empty( $_SERVER[ 'REQUEST_URI' ] ) ) {
$sRestUrlBase = get_rest_url( get_current_blog_id(), '/' );
$sRestPath = trim( parse_url( $sRestUrlBase, PHP_URL_PATH ), '/' );
$sRequestPath = trim( $_SERVER[ 'REQUEST_URI' ], '/' );
$bIsRest = ( strpos( $sRequestPath, $sRestPath ) === 0 );
}
return $bIsRest;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment