-
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
Defer obtaining URL for Customizer preview until AMP Customizer is accessed #6198
Defer obtaining URL for Customizer preview until AMP Customizer is accessed #6198
Conversation
Plugin builds for 5cc5658 are ready 🛎️!
|
Codecov Report
@@ Coverage Diff @@
## develop #6198 +/- ##
=============================================
+ Coverage 75.10% 75.23% +0.13%
- Complexity 5865 5870 +5
=============================================
Files 234 234
Lines 17747 17754 +7
=============================================
+ Hits 13329 13358 +29
+ Misses 4418 4396 -22
Flags with carried forward coverage won't be shown. Click here to find out more.
|
/** | ||
* Add custom analytics. | ||
* | ||
* This is currently only used for legacy AMP post templates. | ||
* | ||
* @since 0.5 | ||
* @see amp_get_analytics() | ||
* @internal | ||
* | ||
* @param array $analytics Analytics. | ||
* @return array Analytics. | ||
*/ | ||
function amp_add_custom_analytics( $analytics = [] ) { | ||
$analytics = amp_get_analytics( $analytics ); | ||
|
||
/** | ||
* Add amp-analytics tags. | ||
* | ||
* This filter allows you to easily insert any amp-analytics tags without needing much heavy lifting. | ||
* This filter should be used to alter entries for legacy AMP templates. | ||
* | ||
* @since 0.4 | ||
* | ||
* @param array $analytics An associative array of the analytics entries we want to output. Each array entry must have a unique key, and the value should be an array with the following keys: `type`, `attributes`, `script_data`. See readme for more details. | ||
* @param WP_Post $post The current post. | ||
*/ | ||
$analytics = apply_filters( 'amp_post_template_analytics', $analytics, get_queried_object() ); | ||
|
||
return $analytics; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was simply moved from includes/admin/functions.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM .
Summary
This addresses a support forum topic:
The issue here is the AMP Customizer link which is added under the Appearance menu when Reader mode is selected:
In order to have the Customizer open with an AMP page in the preview, we do a query to find an AMP page and then supply it in the
url
parameter tocustomize.php
. However, we don't have to supply this URL at this point. We can defer lookup up the URL until the Customizer is actually accessed. We can omit theurl
parameter and instead supply a custom one likeamp_preview
. When that is supplied when accessingcustomize.php
and Reader mode is active, in thecustomize_controls_init
action we can at that point do the lookup for an AMP page and pass it toWP_Customize_Manager::set_preview_url()
. In this way the preview URL will be determined just in time.This only applies in Reader mode to the aforementioned AMP admin menu item under Appearance and also to the “Customize Reader Theme” link on the AMP Settings screen:
This PR also fixes a deprecation notice which was something I missed in #5793.
Checklist