Skip to content

Commit

Permalink
refactor: simplify public route redirection by using template_redirect (
Browse files Browse the repository at this point in the history
  • Loading branch information
apmatthews authored Oct 13, 2021
1 parent 2563121 commit 7be3af0
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions plugins/wpe-headless/includes/deny-public-access/callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 7be3af0

Please sign in to comment.