PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
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 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | modules/likes.php +82 -38 13.3.316.3-a.1 View file →
@@ -1,8 +1,8 @@
1 1 <?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 2 /**
3 3 * Module Name: Likes
4 - * Module Description: Give visitors an easy way to show they appreciate your content.
4 + * Module Description: Let readers like your posts to show appreciation and encourage interaction.
5 5 * First Introduced: 2.2
6 6 * Sort Order: 23
7 7 * Requires Connection: Yes
8 8 * Auto Activate: No
@@ -20,18 +20,39 @@
20 20
21 21 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
22 22
23 23 use Automattic\Jetpack\Assets;
24 +use Automattic\Jetpack\Status\Host;
24 25
25 -Assets::add_resource_hint(
26 - array(
27 - '//widgets.wp.com',
28 - '//s0.wp.com',
29 - '//0.gravatar.com',
30 - '//1.gravatar.com',
31 - '//2.gravatar.com',
32 - ),
33 - 'dns-prefetch'
26 +if ( ! defined( 'ABSPATH' ) ) {
27 + exit( 0 );
28 +}
29 +
30 +add_filter(
31 + 'wp_resource_hints',
32 + function ( $hints, $relation_type ) {
33 + if ( 'dns-prefetch' !== $relation_type ) {
34 + return $hints;
35 + }
36 +
37 + // Only hint on pages where Likes can render.
38 + if ( ! is_singular() && ! is_home() && ! is_front_page() && ! is_archive() && ! is_search() ) {
39 + return $hints;
40 + }
41 +
42 + return array_merge(
43 + $hints,
44 + array(
45 + '//widgets.wp.com',
46 + '//s0.wp.com',
47 + '//0.gravatar.com',
48 + '//1.gravatar.com',
49 + '//2.gravatar.com',
50 + )
51 + );
52 + },
53 + 10,
54 + 2
34 55 );
35 56
36 57 require_once __DIR__ . '/likes/jetpack-likes-master-iframe.php';
37 58 require_once __DIR__ . '/likes/jetpack-likes-settings.php';
@@ -39,9 +60,8 @@
39 60 /**
40 61 * Jetpack Like Class
41 62 */
42 63 class Jetpack_Likes {
43 -
44 64 /**
45 65 * Jetpack_Likes_Settings object
46 66 *
47 67 * @var Jetpack_Likes_Settings
@@ -75,22 +95,33 @@
75 95
76 96 add_action( 'jetpack_activate_module_likes', array( $this, 'set_social_notifications_like' ) );
77 97 add_action( 'jetpack_deactivate_module_likes', array( $this, 'delete_social_notifications_like' ) );
78 98
79 - Jetpack::enable_module_configurable( __FILE__ );
99 + // The `enable_module_configurable` method doesn't exist in the WP.com loader implementation.
100 + if ( ! ( new Host() )->is_wpcom_simple() ) {
101 + Jetpack::enable_module_configurable( __FILE__ );
102 + }
103 +
80 104 add_filter( 'jetpack_module_configuration_url_likes', array( $this, 'jetpack_likes_configuration_url' ) );
81 105 add_action( 'admin_print_scripts-settings_page_sharing', array( $this, 'load_jp_css' ) );
82 106 add_filter( 'sharing_show_buttons_on_row_start', array( $this, 'configuration_target_area' ) );
83 107
84 - $active = Jetpack::get_active_modules();
108 + $publicize_active = Jetpack::is_module_active( 'publicize' );
109 + $sharedaddy_active = Jetpack::is_module_active( 'sharedaddy' );
85 110
86 - if ( in_array( 'publicize', $active, true ) && ! in_array( 'sharedaddy', $active, true ) ) {
111 + if ( $this->settings->needs_own_sharing_menu( $sharedaddy_active ) ) {
112 + /*
113 + * Sharedaddy is what registers Settings > Sharing, and it is off, so we
114 + * register that screen ourselves; our settings are displayed on it.
115 + */
116 + add_action( 'admin_menu', array( $this->settings, 'sharing_menu' ) );
117 + } elseif ( $publicize_active && ! $sharedaddy_active ) {
87 118 // we have a sharing page but not the global options area.
88 119 add_action( 'pre_admin_screen_sharing', array( $this->settings, 'sharing_block' ), 20 );
89 120 add_action( 'pre_admin_screen_sharing', array( $this->settings, 'updated_message' ), -10 );
90 121 }
91 122
92 - if ( ! in_array( 'sharedaddy', $active, true ) ) {
123 + if ( ! $sharedaddy_active ) {
93 124 add_action( 'admin_init', array( $this->settings, 'process_update_requests_if_sharedaddy_not_loaded' ) );
94 125 add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_showbuttonon_init' ), 19 );
95 126 add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_showbuttonon_callback' ), 19 );
96 127 add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) );
@@ -150,9 +181,25 @@
150 181 /**
151 182 * Load scripts and styles for front end.
152 183 */
153 184 public function load_styles_register_scripts() {
154 - wp_enqueue_style( 'jetpack_likes', plugins_url( 'likes/style.css', __FILE__ ), array(), JETPACK__VERSION );
185 + // Likes are only rendered on pages that display post content.
186 + if ( ! is_singular() && ! is_home() && ! is_front_page() && ! is_archive() && ! is_search() ) {
187 + return;
188 + }
189 +
190 + $style_url = Assets::get_file_url_for_environment(
191 + '_inc/build/likes/style.min.css',
192 + 'modules/likes/style.css'
193 + );
194 + wp_enqueue_style( 'jetpack_likes', $style_url, array(), JETPACK__VERSION );
195 + $style_path = plugin_dir_path( JETPACK__PLUGIN_FILE ) . (
196 + /** This filter is documented in projects/plugins/jetpack/load-jetpack.php */
197 + apply_filters( 'jetpack_should_use_minified_assets', true )
198 + ? '_inc/build/likes/style.min.css'
199 + : 'modules/likes/style.css'
200 + );
201 + wp_style_add_data( 'jetpack_likes', 'path', $style_path );
155 202 wp_register_script(
156 203 'jetpack_likes_queuehandler',
157 204 Assets::get_file_url_for_environment(
158 205 '_inc/build/likes/queuehandler.min.js',
@@ -287,16 +334,18 @@
287 334 ?>
288 335 <style type="text/css">
289 336 .vers img { display: none; }
290 337 .metabox-prefs .vers img { display: inline; }
291 - .fixed .column-likes { width: 5.5em; padding: 8px 0; text-align: left; }
292 - .fixed .column-stats { width: 5em; }
338 + .fixed .column-likes { width: 2.5em; padding: 4px 0; text-align: left; }
339 + .fixed .column-stats { width: 5em; white-space: nowrap; }
293 340 .fixed .column-likes .post-com-count {
294 341 -webkit-box-sizing: border-box;
295 342 -moz-box-sizing: border-box;
296 343 box-sizing: border-box;
297 344 display: inline-block;
298 - padding: 0 8px;
345 + padding: 0 4px;
346 + min-width: 2em;
347 + text-align: center;
299 348 height: 2em;
300 349 margin-top: 5px;
301 350 -webkit-border-radius: 5px;
302 351 border-radius: 5px;
@@ -306,9 +355,9 @@
306 355 line-height: 21px;
307 356 }
308 357 .fixed .column-likes .post-com-count::after { border: none !important; }
309 358 .fixed .column-likes .post-com-count:hover { background-color: #2271b1; }
310 - .fixed .column-likes .vers:before {
359 + .fixed .column-likes .vers::before {
311 360 font: normal 20px/1 dashicons;
312 361 content: '\f155';
313 362 speak: none;
314 363 -webkit-font-smoothing: antialiased;
@@ -335,9 +384,9 @@
335 384 'modules/likes/post-count.js'
336 385 ),
337 386 array( 'jquery' ),
338 387 JETPACK__VERSION,
339 - $in_footer = false
388 + false
340 389 );
341 390 wp_enqueue_script(
342 391 'likes-post-count-jetpack',
343 392 Assets::get_file_url_for_environment(
@@ -345,9 +394,9 @@
345 394 'modules/likes/post-count-jetpack.js'
346 395 ),
347 396 array( 'jquery', 'likes-post-count' ),
348 397 JETPACK__VERSION,
349 - $in_footer = false
398 + false
350 399 );
351 400 }
352 401 }
353 402
@@ -417,28 +466,19 @@
417 466 $url = home_url();
418 467 $url_parts = wp_parse_url( $url );
419 468 $domain = $url_parts['host'];
420 469
421 - // Make sure to include the scripts before the iframe otherwise weird things happen.
422 - add_action( 'wp_footer', 'jetpack_likes_master_iframe', 21 );
470 + // Make sure to include the `queuehandler` scripts before the iframe otherwise the script won't find the iframe.
471 + if ( ! has_action( 'wp_footer', 'jetpack_likes_master_iframe' ) ) {
472 + add_action( 'wp_footer', 'jetpack_likes_master_iframe', 21 );
473 + }
423 474
424 475 /**
425 476 * If the same post appears more then once on a page the page goes crazy
426 477 * we need a slightly more unique id / name for the widget wrapper.
427 478 */
428 - $uniqid = uniqid();
429 - /**
430 - * Enable an alternate Likes layout.
431 - *
432 - * @since 12.9
433 - *
434 - * @module likes
435 - *
436 - * @param bool $new_layout Enable the new Likes layout. False by default.
437 - */
438 - $new_layout = apply_filters( 'likes_new_layout', true ) ? '&amp;n=1' : '';
439 -
440 - $src = sprintf( 'https://widgets.wp.com/likes/?ver=%1$s#blog_id=%2$d&amp;post_id=%3$d&amp;origin=%4$s&amp;obj_id=%2$d-%3$d-%5$s%6$s', rawurlencode( JETPACK__VERSION ), $blog_id, $post_id, $domain, $uniqid, $new_layout );
479 + $uniqid = uniqid();
480 + $src = sprintf( 'https://widgets.wp.com/likes/?ver=%1$s#blog_id=%2$d&amp;post_id=%3$d&amp;origin=%4$s&amp;obj_id=%2$d-%3$d-%5$s', rawurlencode( JETPACK__VERSION ), $blog_id, $post_id, $domain, $uniqid );
441 481 $name = sprintf( 'like-post-frame-%1$d-%2$d-%3$s', $blog_id, $post_id, $uniqid );
442 482 $wrapper = sprintf( 'like-post-wrapper-%1$d-%2$d-%3$s', $blog_id, $post_id, $uniqid );
443 483 $headline = sprintf(
444 484 /** This filter is already documented in modules/sharedaddy/sharing-service.php */
@@ -447,11 +487,15 @@
447 487 );
448 488
449 489 $title = esc_html__( 'Like or Reblog', 'jetpack' );
450 490
491 + /** This filter is documented in modules/likes/jetpack-likes-master-iframe.php */
492 + $src = apply_filters( 'jetpack_likes_iframe_src', $src );
493 +
451 494 $html = "<div class='sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded' id='$wrapper' data-src='$src' data-name='$name' data-title='$title'>";
452 495 $html .= $headline;
453 - $html .= "<div class='likes-widget-placeholder post-likes-widget-placeholder' style='height: 55px;'><span class='button'><span>" . esc_html__( 'Like', 'jetpack' ) . '</span></span> <span class="loading">' . esc_html__( 'Loading...', 'jetpack' ) . '</span></div>';
496 + require_once JETPACK__PLUGIN_DIR . '_inc/lib/class-jetpack-spinner.php';
497 + $html .= "<div class='likes-widget-placeholder post-likes-widget-placeholder' style='height: 55px;'><span class='button'><span>" . esc_html__( 'Like', 'jetpack' ) . '</span></span> <span class="loading">' . Jetpack_Spinner::render( 18 ) . '<span class="screen-reader-text">' . esc_html__( 'Loading…', 'jetpack' ) . '</span></span></div>';
454 498 $html .= "<span class='sd-text-color'></span><a class='sd-link-color'></a>";
455 499 $html .= '</div>';
456 500
457 501 // Let's make sure that the script is enqueued.