Skip to content

Commit

Permalink
fix: Potential Infinite loop caused by nested pre_get_posts hooks p…
Browse files Browse the repository at this point in the history
…atched (#853)

* fix: Potential Infinite loop caused by nested `pre_get_posts` hooks patched

* fix: syntax error fixed
  • Loading branch information
kidunot89 authored May 17, 2024
1 parent f1d96be commit 539f514
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion includes/utils/class-protected-router.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ class Protected_Router {
*/
private function __construct() {
self::$route = woographql_setting( 'authorizing_url_endpoint', apply_filters( 'woographql_authorizing_url_endpoint', self::$default_route ) );

$this->init();
}

/**
* Initialize the Protected_Router class
*
* @return void
*/
private function init() {
/**
* Create the rewrite rule for the route
*/
Expand Down Expand Up @@ -181,14 +191,19 @@ public static function is_auth_request() {
* @return void
*/
public function resolve_request() {
/**
* Remove the resolve_request function from the pre_get_posts action
* to prevent an infinite loop
*/
remove_action( 'pre_get_posts', [ $this, 'resolve_request' ], 1 );

/**
* Access the $wp_query object
*/
global $wp_query;

/**
* Ensure we're on the registered route for graphql route
* Ensure we're on the registered route for the transfer
*/
if ( ! $this->is_auth_request() ) {
return;
Expand Down

0 comments on commit 539f514

Please sign in to comment.