Last active
August 27, 2024 17:03
-
-
Save jasonbahl/5dd6c046cd5a5d39bda9eaaf7e32a09d to your computer and use it in GitHub Desktop.
Disable frontend but allow REST, CRON and GraphQL Requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'parse_request', 'disable_front_end', 99 ); | |
function disable_front_end() { | |
global $wp; | |
/** | |
* If the request is not part of a CRON, REST Request, GraphQL Request or Admin request, | |
* output some basic, blank markup | |
*/ | |
if ( | |
! defined( 'DOING_CRON' ) && | |
! defined( 'REST_REQUEST' ) && | |
! is_admin() && | |
( | |
empty( $wp->query_vars['rest_oauth1'] ) && | |
! defined( 'GRAPHQL_HTTP_REQUEST' ) | |
) | |
) { | |
echo '<!doctype html><html><body> </body></html>'; | |
exit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this
For anyone looking to redirect instead of echo a blank document try:
header('Location:https://<domain-name>/' . $wp->request, true, 301 ); exit();