From 5a11621b087cfc49d81dcd5c1a77d5371ee30c00 Mon Sep 17 00:00:00 2001 From: Andrew Matthews Date: Tue, 12 Oct 2021 18:04:46 -0400 Subject: [PATCH] refactor: simplify public route redirection by using template_redirect --- .../includes/deny-public-access/callbacks.php | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/plugins/wpe-headless/includes/deny-public-access/callbacks.php b/plugins/wpe-headless/includes/deny-public-access/callbacks.php index 9771a6b8a..9385af1d8 100644 --- a/plugins/wpe-headless/includes/deny-public-access/callbacks.php +++ b/plugins/wpe-headless/includes/deny-public-access/callbacks.php @@ -9,31 +9,20 @@ exit; } -add_action( 'parse_request', 'wpe_headless_deny_public_access', 99 ); +add_action( 'template_redirect', 'wpe_headless_deny_public_access', 99 ); /** * Redirects non-API requests for public URLs to the specified front-end URL. * - * @param object $query The current query. - * * @return void */ -function wpe_headless_deny_public_access( $query ) { - if ( ! wpe_headless_is_redirects_enabled() ) { +function wpe_headless_deny_public_access() { + if ( ! wpe_headless_is_redirects_enabled() || is_customize_preview() ) { return; } $frontend_uri = wpe_headless_get_setting( 'frontend_uri' ); - if ( - defined( 'DOING_CRON' ) || - defined( 'REST_REQUEST' ) || - is_admin() || - is_customize_preview() || - ( function_exists( 'is_graphql_http_request' ) && is_graphql_http_request() ) || // From https://wordpress.org/plugins/wp-graphql/. - ! empty( $query->query_vars['rest_oauth1'] ) || // From https://oauth1.wp-api.org/. - ! property_exists( $query, 'request' ) || - ! $frontend_uri - ) { + if ( ! $frontend_uri ) { return; }