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();