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

Only unauthenticate user when parse_query is for the main query #712

Merged
merged 2 commits into from
Apr 15, 2022

Conversation

westonruter
Copy link
Collaborator

@westonruter westonruter commented Feb 26, 2022

This is a follow-up to #279 and it addresses a conflict with Polylang identified in a support topic.

The issue is that if a WP_Query instance is created before the main query, then this can result in our wp_unauthenticate_error_template_requests() running on the parse_query action when there is no $wp_query global yet set. The result is a notice:

PHP Notice: is_offline was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.0.) in /app/public/core-dev/src/wp-includes/functions.php on line 5768

The fix is simply to ensure that the query being parsed is the main query, because that will ensure that the $wp_the_query has been set, at which point the $wp_query global has already been set.

Fixes #538.

@westonruter westonruter added this to the 0.7 milestone Feb 26, 2022
@westonruter westonruter added bug Something isn't working service-workers labels Feb 26, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #712 (8a7880f) into develop (749a985) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             develop     #712   +/-   ##
==========================================
  Coverage      19.96%   19.96%           
  Complexity       326      326           
==========================================
  Files             56       56           
  Lines           2094     2094           
==========================================
  Hits             418      418           
  Misses          1676     1676           
Flag Coverage Δ
php 19.96% <100.00%> (ø)
unit 19.96% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
wp-includes/general-template.php 9.09% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 749a985...8a7880f. Read the comment docs.

@@ -75,4 +75,24 @@ public function test_wp_unauthenticate_error_template_requests( $request_url, $a
$this->assertEquals( 0, get_current_user_id() );
}
}

/**
* Test that that `wp_unauthenticate_error_template_requests()` running at the `parse_query` action doesn't cause
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Test that that `wp_unauthenticate_error_template_requests()` running at the `parse_query` action doesn't cause
* Test that `wp_unauthenticate_error_template_requests()` running at the `parse_query` action doesn't cause

Copy link
Collaborator

@thelovekesh thelovekesh left a comment

Choose a reason for hiding this comment

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

Changes LGTM 👍🏼

@westonruter westonruter merged commit 3206f03 into develop Apr 15, 2022
@westonruter westonruter deleted the fix/main-query-check-for-unauthenticating-user branch April 15, 2022 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PHP Notice: is_offline was called incorrectly
3 participants