Skip to content

Commit 025161a

Browse files
jehervegravityrail
andauthored
Comment Likes: do not load on AMP views (#14840)
* Prevent noticons from being enqueued in AMP mode Summary: This patch disables enqueuing of assets for some non-functional features when in AMP mode. Noticons is a very large CSS asset, and so it prevents a lot of other CSS from being enqueued. A review of the places we use it showed that it was not actually being used by any functionality that works in AMP mode. Affected features: - Comment Likes (non-functional in AMP) - Geo Location (not used on most pages - might be useful to port `wpcom_vip_load_geolocation_styles_only_when_needed()` to all sites) - Notifications UI (non-functional in AMP) - admin-bar - (non-functional in AMP) Test Plan: Load a page in Transitional mode Ensure that noticons-css is not enqueued, and that little or no CSS is blocked by AMP due to being over the 50kb max [x] - ensure that features whose CSS is not being enqueued are not actually used Reviewers: josephscott, #devops_team, davidbinovec, goldsounds Subscribers: davidbinovec Tags: #touches_jetpack_files Differential Revision: D38340-code This commit syncs r203534-wpcom. * AMP: fix linting issues introduced in D38340 Summary: The file is synced with Jetpack, and D38340 cannot be merged into Jetpack as is as it introduces changes that will not pass our pre-commit hook. This diff fixes all PHPCS warnings. Test Plan: * Not much to test here, this only impacts documentation / comments. Reviewers: goldsounds Tags: #touches_jetpack_files Differential Revision: D39590 This commit syncs r r203555-wpcom. Co-authored-by: Daniel Walmsley <[email protected]>
1 parent 0365248 commit 025161a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

3rd-party/class.jetpack-amp-support.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public static function init() {
4141
// Post rendering changes for legacy AMP.
4242
add_action( 'pre_amp_render_post', array( 'Jetpack_AMP_Support', 'amp_disable_the_content_filters' ) );
4343

44+
// Transitional mode AMP should not have comment likes.
45+
add_action( 'the_content', array( 'Jetpack_AMP_Support', 'disable_comment_likes_before_the_content' ) );
46+
4447
// Add post template metadata for legacy AMP.
4548
add_filter( 'amp_post_template_metadata', array( 'Jetpack_AMP_Support', 'amp_post_template_metadata' ), 10, 2 );
4649

@@ -49,6 +52,28 @@ public static function init() {
4952

5053
// Sync the amp-options.
5154
add_filter( 'jetpack_options_whitelist', array( 'Jetpack_AMP_Support', 'filter_jetpack_options_whitelist' ) );
55+
56+
// Show admin bar.
57+
add_filter( 'show_admin_bar', array( 'Jetpack_AMP_Support', 'show_admin_bar' ) );
58+
add_filter( 'jetpack_comment_likes_enabled', array( 'Jetpack_AMP_Support', 'comment_likes_enabled' ) );
59+
}
60+
61+
/**
62+
* Disable the admin bar on AMP views.
63+
*
64+
* @param Whether bool $show the admin bar should be shown. Default false.
65+
*/
66+
public static function show_admin_bar( $show ) {
67+
return $show && ! self::is_amp_request();
68+
}
69+
70+
/**
71+
* Disable the Comment Likes feature on AMP views.
72+
*
73+
* @param bool $enabled Should comment likes be enabled.
74+
*/
75+
public static function comment_likes_enabled( $enabled ) {
76+
return $enabled && ! self::is_amp_request();
5277
}
5378

5479
/**
@@ -101,6 +126,18 @@ public static function amp_disable_the_content_filters() {
101126
remove_filter( 'pre_kses', array( 'Filter_Embedded_HTML_Objects', 'maybe_create_links' ), 100 );
102127
}
103128

129+
/**
130+
* Do not add comment likes on AMP requests.
131+
*
132+
* @param string $content Post content.
133+
*/
134+
public static function disable_comment_likes_before_the_content( $content ) {
135+
if ( self::is_amp_request() ) {
136+
remove_filter( 'comment_text', 'comment_like_button', 12, 2 );
137+
}
138+
return $content;
139+
}
140+
104141
/**
105142
* Add Jetpack stats pixel.
106143
*

0 commit comments

Comments
 (0)