Skip to content

Commit 0a437ce

Browse files
authored
AMP: allow the display of the admin bar in AMP views. (#15372)
* AMP: allow the display of the admin bar in AMP views. Fixes #15353 The admin bar can be used in AMP views since AMP 1.3.1, thanks to AMP Dev mode. * Likes: do not load Likes in admin bar on AMP views
1 parent e6104b2 commit 0a437ce

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ 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+
// Disable Comment Likes.
45+
add_filter( 'jetpack_comment_likes_enabled', array( 'Jetpack_AMP_Support', 'comment_likes_enabled' ) );
46+
4447
// Transitional mode AMP should not have comment likes.
45-
add_action( 'the_content', array( 'Jetpack_AMP_Support', 'disable_comment_likes_before_the_content' ) );
48+
add_filter( 'the_content', array( 'Jetpack_AMP_Support', 'disable_comment_likes_before_the_content' ) );
49+
50+
// Remove the Likes button from the admin bar.
51+
add_filter( 'jetpack_admin_bar_likes_enabled', array( 'Jetpack_AMP_Support', 'disable_likes_admin_bar' ) );
4652

4753
// Add post template metadata for legacy AMP.
4854
add_filter( 'amp_post_template_metadata', array( 'Jetpack_AMP_Support', 'amp_post_template_metadata' ), 10, 2 );
@@ -52,19 +58,6 @@ public static function init() {
5258

5359
// Sync the amp-options.
5460
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();
6861
}
6962

7063
/**
@@ -138,6 +131,18 @@ public static function disable_comment_likes_before_the_content( $content ) {
138131
return $content;
139132
}
140133

134+
/**
135+
* Do not display the Likes' Admin bar on AMP requests.
136+
*
137+
* @param bool $is_admin_bar_button_visible Should the Like button be visible in the Admin bar. Default to true.
138+
*/
139+
public static function disable_likes_admin_bar( $is_admin_bar_button_visible ) {
140+
if ( self::is_amp_request() ) {
141+
return false;
142+
}
143+
return $is_admin_bar_button_visible;
144+
}
145+
141146
/**
142147
* Add Jetpack stats pixel.
143148
*

0 commit comments

Comments
 (0)