-
Notifications
You must be signed in to change notification settings - Fork 382
Description
Bug Description
When calling is_amp_endpoints() at an early stage in a plugin, the conditionals is_embed() en is_feed() issue an error notice, saying it can't be used before the query is finished. It doesn't reach the code that is used to test if the function is started too early, so the cause is unclear at first.
Expected Behaviour
The function tests if it is started before the 'parse_query' hook and starts doing_it_wrong saying is_amp_endpoint() it is started to early in the process. This would be the intended behaviour when it is started too early. it would be solved by moving the if(! $did_parse_query) block up so it runs and before testing the template tags. now it doesn't reach that test depending on how early it is called.
Steps to reproduce
- Add a if statement with the condition is_amp_embed() at the global level of a plugin
- activate the plugin
- refresh a page at the website's frontend.
- See error in the log (or whoops)
Screenshots
the notice is:
is_embed 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.)
Additional context
- WordPress version: 5.4
- Plugin version: 1.5.2
- PHP version: 7.3.2
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation brief
QA testing instructions
Demo
Changelog entry
- Improve the
_doing_it_wrong()
message for whenis_amp_endpoint()
is called before thewp
action. - Account for additional template conditionals:
is_comment_feed()
,is_trackback()
,is_robots()
, andis_favicon()
. - Remove special condition to allow
is_amp_endpoint()
to not emit_doing_it_wrong()
when called beforewp
when in Reader mode. - Prevent emitting
_doing_it_wrong()
errors when by callingis_embed()
oris_feed()
before they are able to be called. - Prevent emitting duplicated warnings.
- Remove separate condition for doing redirects to non-AMP when AMP is not available in Reader mode.
- Remove unnecessary
exit
logic. - Fix ability to access the
page_for_posts
if designated to be enabled in AMP Reader mode.