PreGetPosts: improve the isEarlyMainQueryCheck() method #565
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a unit test which results in the error as reported in issue #499 and fixes the error properly.
The error was caused by the presumption in the code that if a check for
is_main_query
has a scope condition which is aclosure
, that theclosure
is the callback in the hook function call and that therefore the outer parenthesis (those of the function call) should be disgarded and the next parenthesis will be the ones for theif
statement which will always have a scope opener and closer.Now read the above sentence again and count the number of assumptions in that statement ;-)
Either way, the fix I've now added should stabilize this part of the code.
Fixes #499
[Edit] I've added a second commit to the code after seeing the actual code which was triggering the error.
PreGetPosts: improve the isEarlyMainQueryCheck() method [2]
This adds a second unit test which is based on the actual code which originally triggered the error.
The error was caused by the code in question using inline control structures (without braces) for the early main query check.
After the previous fix, that code would now throw a false positive.
I've fixed this now by adding an additional check for a
return
statement straight after the parenthesis closer of theif()
statement.