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

Fix AMP integration by deferring masterbar setup to wp action #11088

Merged

Conversation

westonruter
Copy link
Contributor

@westonruter westonruter commented Jan 4, 2019

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:

  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:

  • Fix AMP integration with masterbar module.

@westonruter westonruter requested a review from a team January 4, 2019 18:49
@jetpackbot
Copy link

jetpackbot commented Jan 4, 2019

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: January 10, 2019.
Scheduled code freeze: January 3, 2019

Generated by 🚫 dangerJS against a4caf27

@jeherve jeherve added this to the 6.9 milestone Jan 7, 2019
@jeherve jeherve added [Type] Bug When a feature is broken and / or not performing as intended [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Feature] Masterbar WordPress.com Toolbar and Dashboard customizations AMP labels Jan 7, 2019
@jeherve
Copy link
Member

jeherve commented Jan 7, 2019

The changes in #10945 caused some issues with the Masterbar when on the Jetpack dashboard pages, as reported in #11081.

This PR now stops the masterbar from loading at all on those pages. It works well on other pages, though.

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

It seems to work better with admin_bar_init, although I can't really explain why.

modules/masterbar.php Outdated Show resolved Hide resolved
@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Jan 7, 2019
…t in wp-admin

Co-Authored-By: westonruter <westonruter@google.com>
@westonruter
Copy link
Contributor Author

It seems to work better with admin_bar_init, although I can't really explain why.

I think the reason is that in the admin, the wp action happens after admin_bar_init has already happened, whereas on the frontend the order is reversed. Were you seeing the masterbar broken in the admin but working on the frontend?

@jeherve jeherve removed the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Jan 7, 2019
@jeherve
Copy link
Member

jeherve commented Jan 7, 2019

Were you seeing the masterbar broken in the admin but working on the frontend?

Yep, that's what was happening. Thanks for digging into it!

@jeherve jeherve added the [Status] Ready to Merge Go ahead, you can push that green button! label Jan 7, 2019
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This seems to work well on my end. 👍 🚢

@westonruter
Copy link
Contributor Author

Should this be assigned to me now? I can't merge it 😄

@jeherve
Copy link
Member

jeherve commented Jan 8, 2019

No worries :) Someone else will come around, review and merge :)

Copy link
Contributor

@oskosk oskosk left a comment

Choose a reason for hiding this comment

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

LGTM!

@jeherve jeherve merged commit e68654b into Automattic:master Jan 8, 2019
@ghost ghost removed [Status] Needs Changelog [Status] Ready to Merge Go ahead, you can push that green button! labels Jan 8, 2019
@jeherve
Copy link
Member

jeherve commented Jan 8, 2019

Cherry-picked to branch-6.9 in aa64a8c

jeherve pushed a commit 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.
ockham added a commit that referenced this pull request Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AMP [Feature] Masterbar WordPress.com Toolbar and Dashboard customizations [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants