Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify public route redirection by using template_redirect #575

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nickcernis Could you share any context on why this line was required? It seems like most oauth1 requests would have been covered by the defined( 'REST_REQUEST' ) check above, so I want to make sure I'm not missing something by removing it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apmatthews I'd read that REST_REQUEST was undefined if a site is using Plain permalinks, but looking again I'm not sure that's true: https://github.com/WordPress/WordPress/blob/d2694aa46647af48d1bcaff48a4f6cac7f5cf470/wp-includes/rest-api.php#L360

I think it's safe to remove it.

! property_exists( $query, 'request' ) ||
! $frontend_uri
) {
if ( ! $frontend_uri ) {
return;
}

Expand Down