-
Notifications
You must be signed in to change notification settings - Fork 384
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
Add _doing_it_wrong() when calling is_amp_endpoint() before queried object is available #1794
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… action Also make sure that only a WP_Post is passed into AMP_Post_Type_Support::get_support_errors()
westonruter
force-pushed
the
fix/is-endpoint-timing-check
branch
from
January 4, 2019 00:28
2534e2c
to
a0bc752
Compare
felixarntz
reviewed
Jan 4, 2019
felixarntz
approved these changes
Jan 4, 2019
jeherve
pushed a commit
to Automattic/jetpack
that referenced
this pull request
Jan 8, 2019
<!--- Provide a general summary of your changes in the Title above --> Fixes #11082 Fixes #11081 #### Changes proposed in this Pull Request: * Defer masterbar setup until the `wp` action, instead of doing the setup at the `init` action. This is needed because the `is_amp_endpoint()` function cannot be called before the `wp` action, as it needs access to the queried object. #### Testing instructions: <!-- Please include detailed testing steps, explaining how to test your change. --> <!-- Bear in mind that context you working on is not obvious for everyone. --> <!-- Adding "simple" configuration steps will help reviewers to get to your PR as quickly as possible. --> <!-- "Before / After" screenshots can also be very helpful when the change is visual. --> 1. Ensure Jetpack's masterbar module is active. 2. Activate the AMP plugin v1.0.1 3. Enable the new paired mode via the AMP settings. 4. Navigate to a singular post. Without the changes in this PR, there should be two PHP notices being raised: ``` ( ! ) Notice: Trying to get property 'post_type' of non-object in .../amp/includes/class-amp-post-type-support.php on line 80 ( ! ) Notice: Trying to get property 'ID' of non-object in .../amp/includes/class-amp-post-type-support.php on line 101 ``` See also ampproject/amp-wp#1794 which will catch the incorrect usage of `is_amp_endpoint()`. #### Proposed changelog entry for your changes: <!-- Please do not leave this empty. If no changelog entry needed, state as such. --> * Fix AMP integration with masterbar module.
jeherve
pushed a commit
to Automattic/jetpack
that referenced
this pull request
Jan 8, 2019
<!--- Provide a general summary of your changes in the Title above --> Fixes #11082 Fixes #11081 #### Changes proposed in this Pull Request: * Defer masterbar setup until the `wp` action, instead of doing the setup at the `init` action. This is needed because the `is_amp_endpoint()` function cannot be called before the `wp` action, as it needs access to the queried object. #### Testing instructions: <!-- Please include detailed testing steps, explaining how to test your change. --> <!-- Bear in mind that context you working on is not obvious for everyone. --> <!-- Adding "simple" configuration steps will help reviewers to get to your PR as quickly as possible. --> <!-- "Before / After" screenshots can also be very helpful when the change is visual. --> 1. Ensure Jetpack's masterbar module is active. 2. Activate the AMP plugin v1.0.1 3. Enable the new paired mode via the AMP settings. 4. Navigate to a singular post. Without the changes in this PR, there should be two PHP notices being raised: ``` ( ! ) Notice: Trying to get property 'post_type' of non-object in .../amp/includes/class-amp-post-type-support.php on line 80 ( ! ) Notice: Trying to get property 'ID' of non-object in .../amp/includes/class-amp-post-type-support.php on line 101 ``` See also ampproject/amp-wp#1794 which will catch the incorrect usage of `is_amp_endpoint()`. #### Proposed changelog entry for your changes: <!-- Please do not leave this empty. If no changelog entry needed, state as such. --> * Fix AMP integration with masterbar module.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Ever since 0.4.2, the AMP plugin has issued a
_doing_it_wrong()
whenis_amp_endpoint()
is called before theparse_query
action. This was needed to ensure that theamp
query var was parsed and available for inspection.It turns out that this did not go far enough. As of 1.0 the
is_amp_endpoint()
needs to look at the queried object as well to determine whether AMP has been enabled/disabled for a given post on singular queries. The queried object is not available atparse_query
since the posts have not been queried yet at this point. Rather, it is only at thewp
action that we can be assured that$wp_query->post
has been populated and thus that the queried object is present for inspection.Also make sure that only a
WP_Post
is passed intoAMP_Post_Type_Support::get_support_errors()
.Without the changes in this PR, if you have a plugin that does:
You will get PHP notices when viewing a singular post in paired mode:
Changing
parse_query
towp
fixes the issue in plugin code.Issue discovered originally in a Jetpack PR: Automattic/jetpack#10945 (comment)