PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
← All changes | modules/comment-likes.php +27 -24 12.0.3 → 16.3-beta View file →
@@ -1,8 +1,8 @@
1 1 <?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 2 /**
3 3 * Module Name: Comment Likes
4 - * Module Description: Increase visitor engagement by adding a Like button to comments.
4 + * Module Description: Enable visitors to like individual comments and boost engagement.
5 5 * Sort Order: 39
6 6 * Recommendation Order: 17
7 7 * First Introduced: 5.1
8 8 * Requires Connection: Yes
@@ -13,9 +13,14 @@
13 13 * @package automattic/jetpack
14 14 */
15 15
16 16 use Automattic\Jetpack\Assets;
17 +use Automattic\Jetpack\Sharing_Likes\Post_Likes_Switch;
17 18
19 +if ( ! defined( 'ABSPATH' ) ) {
20 + exit( 0 );
21 +}
22 +
18 23 Assets::add_resource_hint( '//widgets.wp.com', 'dns-prefetch' );
19 24
20 25 require_once __DIR__ . '/likes/jetpack-likes-master-iframe.php';
21 26 require_once __DIR__ . '/likes/jetpack-likes-settings.php';
@@ -65,41 +70,32 @@
65 70 private function __construct() {
66 71 $this->settings = new Jetpack_Likes_Settings();
67 72 $this->blog_id = Jetpack_Options::get_option( 'id' );
68 73 $url_parts = wp_parse_url( home_url() );
69 - $this->domain = $url_parts['host'];
70 74
75 + // Abort if domain can't be determined.
76 + if ( ! $url_parts || ! isset( $url_parts['host'] ) ) {
77 + return;
78 + }
79 + $this->domain = $url_parts['host'];
80 +
71 81 add_action( 'template_redirect', array( $this, 'frontend_init' ) );
72 82 add_action( 'admin_init', array( $this, 'admin_init' ) );
73 83
84 + /*
85 + * Comment likes are gated on the Likes settings, so when the Likes module is
86 + * off this module still needs the per-post metabox that carries them.
87 + */
74 88 if ( ! Jetpack::is_module_active( 'likes' ) ) {
75 - $active = Jetpack::get_active_modules();
76 -
77 - if ( ! in_array( 'sharedaddy', $active, true ) && ! in_array( 'publicize', $active, true ) ) {
78 - // we don't have a sharing page yet.
79 - add_action( 'admin_menu', array( $this->settings, 'sharing_menu' ) );
80 - }
81 -
82 - if ( in_array( 'publicize', $active, true ) && ! in_array( 'sharedaddy', $active, true ) ) {
83 - // we have a sharing page but not the global options area.
84 - add_action( 'pre_admin_screen_sharing', array( $this->settings, 'sharing_block' ), 20 );
85 - add_action( 'pre_admin_screen_sharing', array( $this->settings, 'updated_message' ), -10 );
86 - }
87 -
88 - if ( ! in_array( 'sharedaddy', $active, true ) ) {
89 - add_action( 'admin_init', array( $this->settings, 'process_update_requests_if_sharedaddy_not_loaded' ) );
90 - add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_showbuttonon_init' ), 19 );
91 - add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_showbuttonon_callback' ), 19 );
92 - add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) );
93 - } else {
89 + if ( Jetpack::is_module_active( 'sharedaddy' ) ) {
94 90 add_filter( 'sharing_meta_box_title', array( $this->settings, 'add_likes_to_sharing_meta_box_title' ) );
95 91 add_action( 'start_sharing_meta_box_content', array( $this->settings, 'meta_box_content' ) );
92 + } else {
93 + add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) );
96 94 }
97 95
98 96 add_action( 'save_post', array( $this->settings, 'meta_box_save' ) );
99 97 add_action( 'edit_attachment', array( $this->settings, 'meta_box_save' ) );
100 - add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_init' ), 20 );
101 - add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_callback' ), 20 );
102 98 }
103 99 }
104 100
105 101 /**
@@ -166,9 +162,9 @@
166 162 /**
167 163 * Initialize front end
168 164 */
169 165 public function frontend_init() {
170 - if ( Jetpack_AMP_Support::is_amp_request() ) {
166 + if ( class_exists( Jetpack_AMP_Support::class ) && Jetpack_AMP_Support::is_amp_request() ) {
171 167 return;
172 168 }
173 169
174 170 add_action( 'wp_enqueue_scripts', array( $this, 'load_styles_register_scripts' ) );
@@ -213,8 +209,12 @@
213 209 if ( empty( $content ) || empty( $comment_id ) ) {
214 210 return $content;
215 211 }
216 212
213 + if ( empty( $comment->comment_approved ) ) {
214 + return $content;
215 + }
216 +
217 217 // In case master iframe hasn't been loaded. This could be the case when Post Likes module is disabled,
218 218 // or on pages on which we have comments but post likes are disabled.
219 219 if ( false === has_action( 'wp_footer', 'jetpack_likes_master_iframe' ) ) {
220 220 add_action( 'wp_footer', 'jetpack_likes_master_iframe', 21 );
@@ -246,6 +246,9 @@
246 246
247 247 return $content . $like_button;
248 248 }
249 249 }
250 +
251 +// Comment likes follow the per-post Likes switch, so the block editor needs it without the Likes module.
252 +Post_Likes_Switch::init();
250 253
251 254 Jetpack_Comment_Likes::init();