From e68654b865b0e20321427b98c28024e235f37c53 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 8 Jan 2019 03:27:29 -0800 Subject: [PATCH] Fix AMP integration by deferring masterbar setup to wp action (#11088) 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 https://github.com/ampproject/amp-wp/pull/1794 which will catch the incorrect usage of `is_amp_endpoint()`. #### Proposed changelog entry for your changes: * Fix AMP integration with masterbar module. --- modules/masterbar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/masterbar.php b/modules/masterbar.php index 900082930bd38..8efeae3e49bfa 100644 --- a/modules/masterbar.php +++ b/modules/masterbar.php @@ -14,7 +14,7 @@ require dirname( __FILE__ ) . '/masterbar/masterbar.php'; // In order to be able to tell if it's an AMP request or not we have to hook into parse_query at a later priority. -add_action( 'parse_query', 'jetpack_initialize_masterbar', 99 ); +add_action( 'admin_bar_init', 'jetpack_initialize_masterbar', 99 ); /** * Initializes the Masterbar in case the request is not AMP.