PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 11.6.2
Jetpack – WP Security, Backup, Speed, & Growth v11.6.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 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / likes.php

likes.php in Jetpack – WP Security, Backup, Speed, & Growth 11.6.2, at modules/likes.php

614 lines 21.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Module Name: Likes
4 * Module Description: Give visitors an easy way to show they appreciate your content.
5 * First Introduced: 2.2
6 * Sort Order: 23
7 * Requires Connection: Yes
8 * Auto Activate: No
9 * Module Tags: Social
10 * Feature: Engagement
11 * Additional Search Queries: like, likes, wordpress.com
12 *
13 * @package automattic/jetpack
14 */
15 /**
16 * NOTE: While the front-end behavior currently varies, try to keep the data
17 * model here the same as on wpcom to facilitate Simple→Atomic moves and
18 * possible future work to recombine the front-ends.
19 */
20
21 use Automattic\Jetpack\Assets;
22
23 Assets::add_resource_hint(
24 array(
25 '//widgets.wp.com',
26 '//s0.wp.com',
27 '//0.gravatar.com',
28 '//1.gravatar.com',
29 '//2.gravatar.com',
30 ),
31 'dns-prefetch'
32 );
33
34 require_once __DIR__ . '/likes/jetpack-likes-master-iframe.php';
35 require_once __DIR__ . '/likes/jetpack-likes-settings.php';
36
37 /**
38 * Jetpack Like Class
39 */
40 class Jetpack_Likes {
41
42 /**
43 * Initialize class
44 */
45 public static function init() {
46 static $instance = null;
47
48 if ( ! $instance ) {
49 $instance = new Jetpack_Likes();
50 }
51
52 return $instance;
53 }
54
55 /**
56 * Constructs Likes class
57 */
58 public function __construct() {
59 $this->settings = new Jetpack_Likes_Settings();
60
61 // We need to run on wp hook rather than init because we check is_amp_endpoint()
62 // when bootstrapping hooks.
63 add_action( 'wp', array( $this, 'action_init' ), 99 );
64
65 add_action( 'admin_init', array( $this, 'admin_init' ) );
66
67 add_action( 'jetpack_activate_module_likes', array( $this, 'set_social_notifications_like' ) );
68 add_action( 'jetpack_deactivate_module_likes', array( $this, 'delete_social_notifications_like' ) );
69
70 Jetpack::enable_module_configurable( __FILE__ );
71 add_filter( 'jetpack_module_configuration_url_likes', array( $this, 'jetpack_likes_configuration_url' ) );
72 add_action( 'admin_print_scripts-settings_page_sharing', array( $this, 'load_jp_css' ) );
73 add_filter( 'sharing_show_buttons_on_row_start', array( $this, 'configuration_target_area' ) );
74
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 {
94 add_filter( 'sharing_meta_box_title', array( $this->settings, 'add_likes_to_sharing_meta_box_title' ) );
95 add_action( 'start_sharing_meta_box_content', array( $this->settings, 'meta_box_content' ) );
96 }
97
98 add_action( 'admin_init', array( $this, 'admin_discussion_likes_settings_init' ) ); // Likes notifications.
99
100 add_action( 'admin_bar_menu', array( $this, 'admin_bar_likes' ), 60 );
101
102 add_action( 'wp_enqueue_scripts', array( $this, 'load_styles_register_scripts' ) );
103
104 add_action( 'save_post', array( $this->settings, 'meta_box_save' ) );
105 add_action( 'edit_attachment', array( $this->settings, 'meta_box_save' ) );
106 add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_init' ), 20 );
107 add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_callback' ), 20 );
108 }
109
110 /**
111 * Set the social_notifications_like option to `on` when the Likes module is activated.
112 *
113 * @since 3.7.0
114 */
115 public function set_social_notifications_like() {
116 update_option( 'social_notifications_like', 'on' );
117 }
118
119 /**
120 * Delete the social_notifications_like option that was set to `on` on module activation.
121 *
122 * @since 3.7.0
123 */
124 public function delete_social_notifications_like() {
125 delete_option( 'social_notifications_like' );
126 }
127
128 /**
129 * Overrides default configuration url
130 *
131 * @uses admin_url
132 * @return string module settings URL
133 */
134 public function jetpack_likes_configuration_url() {
135 return admin_url( 'options-general.php?page=sharing#likes' );
136 }
137
138 /**
139 * Loads Jetpack's CSS on the sharing page so we can use .jetpack-targetable
140 */
141 public function load_jp_css() {
142 /**
143 * Do we really need `admin_styles`? With the new admin UI, it's breaking some bits.
144 * Jetpack::init()->admin_styles();
145 */
146 }
147
148 /**
149 * Load scripts and styles for front end.
150 */
151 public function load_styles_register_scripts() {
152 wp_enqueue_style( 'jetpack_likes', plugins_url( 'likes/style.css', __FILE__ ), array(), JETPACK__VERSION );
153 wp_register_script(
154 'jetpack_likes_queuehandler',
155 Assets::get_file_url_for_environment(
156 '_inc/build/likes/queuehandler.min.js',
157 'modules/likes/queuehandler.js'
158 ),
159 array(),
160 JETPACK__VERSION,
161 true
162 );
163 }
164
165 /**
166 * Adds in the jetpack-targetable class so when we visit sharing#likes our like settings get highlighted by a yellow box
167 *
168 * @param string $html row heading for the sharedaddy "which page" setting.
169 * @return string $html with the jetpack-targetable class and likes id. tbody gets closed after the like settings
170 */
171 public function configuration_target_area( $html = '' ) {
172 $html = "<tbody id='likes' class='jetpack-targetable'>" . $html;
173 return $html;
174 }
175
176 /**
177 * Options to be added to the discussion page (see also admin_settings_init, etc below for Sharing settings page)
178 */
179 public function admin_discussion_likes_settings_init() {
180 // Add a temporary section, until we can move the setting out of there and with the rest of the email notification settings.
181 add_settings_section( 'likes-notifications', __( 'Likes Notifications', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_section' ), 'discussion' );
182 add_settings_field( 'social-notifications', __( 'Email me whenever', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_field' ), 'discussion', 'likes-notifications' );
183 // Register the setting.
184 register_setting( 'discussion', 'social_notifications_like', array( $this, 'admin_discussion_likes_settings_validate' ) );
185 }
186
187 /** Add email notification options to WordPress discussion settings */
188 public function admin_discussion_likes_settings_section() {
189 // Atypical usage here. We emit jquery to move likes notification checkbox to be with the rest of the email notification settings.
190 ?>
191 <script type="text/javascript">
192 jQuery( function( $ ) {
193 var table = $( '#social_notifications_like' ).parents( 'table:first' ),
194 header = table.prevAll( 'h2:first' ),
195 newParent = $( '#moderation_notify' ).parent( 'label' ).parent();
196
197 if ( !table.length || !header.length || !newParent.length ) {
198 return;
199 }
200
201 newParent.append( '<br/>' ).append( table.end().parent( 'label' ).siblings().andSelf() );
202 header.remove();
203 table.remove();
204 } );
205 </script>
206 <?php
207 }
208
209 /** Check if email notifications for likes is on or off.
210 *
211 * @param string $option - which option we're checking (social_notifications_like).
212 */
213 public function admin_likes_get_option( $option ) {
214 $option_setting = get_option( $option, 'on' );
215
216 return (int) ( 'on' === $option_setting );
217 }
218
219 /** Display email notification for likes setting in WordPress' discussion settings. */
220 public function admin_discussion_likes_settings_field() {
221 $like = $this->admin_likes_get_option( 'social_notifications_like' );
222 ?>
223 <label><input type="checkbox" id="social_notifications_like" name="social_notifications_like" value="1" <?php checked( $like ); ?> /> <?php esc_html_e( 'Someone likes one of my posts', 'jetpack' ); ?></label>
224 <?php
225 }
226
227 /**
228 * Validate email notification settings.
229 *
230 * @param string $input - determines if checbox is on or off.
231 */
232 public function admin_discussion_likes_settings_validate( $input ) {
233 // If it's not set (was unchecked during form submission) or was set to off (during option update), return 'off'.
234 if ( ! $input || 'off' === $input ) {
235 return 'off';
236 }
237 // Otherwise return 'on'.
238 return 'on';
239 }
240
241 /** Initialize admin settings */
242 public function admin_init() {
243 add_filter( 'manage_posts_columns', array( $this, 'add_like_count_column' ) );
244 add_filter( 'manage_pages_columns', array( $this, 'add_like_count_column' ) );
245 add_action( 'manage_posts_custom_column', array( $this, 'likes_edit_column' ), 10, 2 );
246 add_action( 'manage_pages_custom_column', array( $this, 'likes_edit_column' ), 10, 2 );
247 add_action( 'admin_print_styles-edit.php', array( $this, 'load_admin_css' ) );
248 add_action( 'admin_print_scripts-edit.php', array( $this, 'enqueue_admin_scripts' ) );
249 }
250
251 /** Initialize action */
252 public function action_init() {
253 /*
254 * Only check if the module is enabled here because
255 * we are not currently in The Loop and do not yet have access to check
256 * the switch_like_status post meta flag for the post to be loaded.
257 */
258 if ( is_admin() || ! $this->settings->is_likes_module_enabled() ) {
259 return;
260 }
261
262 if ( ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ||
263 ( defined( 'APP_REQUEST' ) && APP_REQUEST ) ||
264 ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) ||
265 ( defined( 'COOKIE_AUTH_REQUEST' ) && COOKIE_AUTH_REQUEST ) ||
266 ( defined( 'JABBER_SERVER' ) && JABBER_SERVER ) ) {
267 return;
268 }
269
270 if (
271 class_exists( 'Jetpack_AMP_Support' )
272 && Jetpack_AMP_Support::is_amp_request()
273 ) {
274 return;
275 }
276
277 add_filter( 'the_content', array( $this, 'post_likes' ), 30, 1 );
278 add_filter( 'the_excerpt', array( $this, 'post_likes' ), 30, 1 );
279 }
280
281 /**
282 * Load the CSS needed for the wp-admin area.
283 */
284 public function load_admin_css() {
285 ?>
286 <style type="text/css">
287 .vers img { display: none; }
288 .metabox-prefs .vers img { display: inline; }
289 .fixed .column-likes { width: 5.5em; padding: 8px 0; text-align: left; }
290 .fixed .column-stats { width: 5em; }
291 .fixed .column-likes .post-com-count {
292 -webkit-box-sizing: border-box;
293 -moz-box-sizing: border-box;
294 box-sizing: border-box;
295 display: inline-block;
296 padding: 0 8px;
297 height: 2em;
298 margin-top: 5px;
299 -webkit-border-radius: 5px;
300 border-radius: 5px;
301 background-color: #787c82;
302 color: #FFF;
303 font-size: 11px;
304 line-height: 21px;
305 }
306 .fixed .column-likes .post-com-count::after { border: none !important; }
307 .fixed .column-likes .post-com-count:hover { background-color: #2271b1; }
308 .fixed .column-likes .vers:before {
309 font: normal 20px/1 dashicons;
310 content: '\f155';
311 speak: none;
312 -webkit-font-smoothing: antialiased;
313 -moz-osx-font-smoothing: grayscale;
314 }
315 @media screen and (max-width: 782px) {
316 .fixed .column-likes {
317 display: none;
318 }
319 }
320 </style>
321 <?php
322 }
323
324 /**
325 * Load the JS required for loading the like counts.
326 */
327 public function enqueue_admin_scripts() {
328 if ( empty( $_GET['post_type'] ) || 'post' === $_GET['post_type'] || 'page' === $_GET['post_type'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
329 wp_enqueue_script(
330 'likes-post-count',
331 Assets::get_file_url_for_environment(
332 '_inc/build/likes/post-count.min.js',
333 'modules/likes/post-count.js'
334 ),
335 array( 'jquery' ),
336 JETPACK__VERSION,
337 $in_footer = false
338 );
339 wp_enqueue_script(
340 'likes-post-count-jetpack',
341 Assets::get_file_url_for_environment(
342 '_inc/build/likes/post-count-jetpack.min.js',
343 'modules/likes/post-count-jetpack.js'
344 ),
345 array( 'likes-post-count' ),
346 JETPACK__VERSION,
347 $in_footer = false
348 );
349 }
350 }
351
352 /**
353 * Add "Likes" column data to the post edit table in wp-admin.
354 *
355 * @param string $column_name - name of the column.
356 * @param int $post_id - the post id.
357 */
358 public function likes_edit_column( $column_name, $post_id ) {
359 if ( 'likes' === $column_name ) {
360
361 $blog_id = Jetpack_Options::get_option( 'id' );
362
363 $permalink = get_permalink( get_the_ID() );
364 ?>
365 <a title="" data-post-id="<?php echo (int) $post_id; ?>" class="post-com-count post-like-count" id="post-like-count-<?php echo (int) $post_id; ?>" data-blog-id="<?php echo (int) $blog_id; ?>" href="<?php echo esc_url( $permalink ); ?>#like-<?php echo (int) $post_id; ?>">
366 <span class="comment-count">0</span>
367 </a>
368 <?php
369 }
370 }
371
372 /**
373 * Add a "Likes" column header to the post edit table in wp-admin.
374 *
375 * @param array $columns - array of columns in wp-admin.
376 */
377 public function add_like_count_column( $columns ) {
378 $date = $columns['date'];
379 unset( $columns['date'] );
380
381 $columns['likes'] = '<span class="vers"><img title="' . esc_attr__( 'Likes', 'jetpack' ) . '" alt="' . esc_attr__( 'Likes', 'jetpack' ) . '" src="//s0.wordpress.com/i/like-grey-icon.png" /><span class="screen-reader-text">' . __( 'Likes', 'jetpack' ) . '</span></span>';
382 $columns['date'] = $date;
383
384 return $columns;
385 }
386
387 /**
388 * Append like button to content.
389 *
390 * @param string $content - content of the page.
391 */
392 public function post_likes( $content ) {
393 global $wp_current_filter;
394 $post_id = get_the_ID();
395
396 if ( ! is_numeric( $post_id ) || ! $this->settings->is_likes_visible() ) {
397 return $content;
398 }
399
400 // Ensure we don't display like button on post excerpts that are hooked inside the post content
401 if ( in_array( 'the_excerpt', (array) $wp_current_filter, true ) &&
402 in_array( 'the_content', (array) $wp_current_filter, true ) ) {
403 return $content;
404 }
405
406 $blog_id = Jetpack_Options::get_option( 'id' );
407 $url = home_url();
408 $url_parts = wp_parse_url( $url );
409 $domain = $url_parts['host'];
410
411 // Make sure to include the scripts before the iframe otherwise weird things happen.
412 add_action( 'wp_footer', 'jetpack_likes_master_iframe', 21 );
413
414 /**
415 * If the same post appears more then once on a page the page goes crazy
416 * we need a slightly more unique id / name for the widget wrapper.
417 */
418 $uniqid = uniqid();
419
420 $src = sprintf( 'https://widgets.wp.com/likes/#blog_id=%1$d&amp;post_id=%2$d&amp;origin=%3$s&amp;obj_id=%1$d-%2$d-%4$s', $blog_id, $post_id, $domain, $uniqid );
421 $name = sprintf( 'like-post-frame-%1$d-%2$d-%3$s', $blog_id, $post_id, $uniqid );
422 $wrapper = sprintf( 'like-post-wrapper-%1$d-%2$d-%3$s', $blog_id, $post_id, $uniqid );
423 $headline = sprintf(
424 /** This filter is already documented in modules/sharedaddy/sharing-service.php */
425 apply_filters( 'jetpack_sharing_headline_html', '<h3 class="sd-title">%s</h3>', esc_html__( 'Like this:', 'jetpack' ), 'likes' ),
426 esc_html__( 'Like this:', 'jetpack' )
427 );
428
429 $title = esc_html__( 'Like or Reblog', 'jetpack' );
430
431 $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'>";
432 $html .= $headline;
433 $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>';
434 $html .= "<span class='sd-text-color'></span><a class='sd-link-color'></a>";
435 $html .= '</div>';
436
437 // Let's make sure that the script is enqueued.
438 wp_enqueue_script( 'jetpack_likes_queuehandler' );
439
440 return $content . $html;
441 }
442
443 /** Checks if admin bar is visible.*/
444 public function is_admin_bar_button_visible() {
445 global $wp_admin_bar;
446
447 if ( ! is_object( $wp_admin_bar ) ) {
448 return false;
449 }
450
451 if ( ( ! is_singular( 'post' ) && ! is_attachment() && ! is_page() ) ) {
452 return false;
453 }
454
455 if ( ! $this->settings->is_likes_visible() ) {
456 return false;
457 }
458
459 if ( ! $this->settings->is_post_likeable() ) {
460 return false;
461 }
462
463 /**
464 * Filters whether the Like button is enabled in the admin bar.
465 *
466 * @module likes
467 *
468 * @since 2.2.0
469 *
470 * @param bool true Should the Like button be visible in the Admin bar. Default to true.
471 */
472 return (bool) apply_filters( 'jetpack_admin_bar_likes_enabled', true );
473 }
474
475 /** Adds like section in admin bar. */
476 public function admin_bar_likes() {
477 global $wp_admin_bar;
478
479 $post_id = get_the_ID();
480
481 if ( ! is_numeric( $post_id ) || ! $this->is_admin_bar_button_visible() ) {
482 return;
483 }
484
485 $protocol = 'http';
486 if ( is_ssl() ) {
487 $protocol = 'https';
488 }
489 $blog_id = Jetpack_Options::get_option( 'id' );
490 $url = home_url();
491 $url_parts = wp_parse_url( $url );
492 $domain = $url_parts['host'];
493
494 // Make sure to include the scripts before the iframe otherwise weird things happen.
495 add_action( 'wp_footer', 'jetpack_likes_master_iframe', 21 );
496
497 $src = sprintf( 'https://widgets.wp.com/likes/#blog_id=%2$d&amp;post_id=%3$d&amp;origin=%1$s://%4$s', $protocol, $blog_id, $post_id, $domain );
498
499 $html = "<iframe class='admin-bar-likes-widget jetpack-likes-widget' scrolling='no' frameBorder='0' name='admin-bar-likes-widget' src='$src'></iframe>";
500
501 $node = array(
502 'id' => 'admin-bar-likes-widget',
503 'meta' => array(
504 'html' => $html,
505 ),
506 );
507
508 $wp_admin_bar->add_node( $node );
509 }
510 }
511
512 /**
513 * Callback to get the value for the jetpack_likes_enabled field.
514 *
515 * Warning: this behavior is somewhat complicated!
516 * When the switch_like_status post_meta is unset, we follow the global setting in Sharing.
517 * When it is set to 0, we disable likes on the post, regardless of the global setting.
518 * When it is set to 1, we enable likes on the post, regardless of the global setting.
519 *
520 * @param array $post - post data we're checking.
521 */
522 function jetpack_post_likes_get_value( array $post ) {
523 $post_likes_switched = get_post_meta( $post['id'], 'switch_like_status', true );
524
525 /** This filter is documented in modules/jetpack-likes-settings.php */
526 $sitewide_likes_enabled = (bool) apply_filters( 'wpl_is_enabled_sitewide', ! get_option( 'disabled_likes' ) );
527
528 // An empty string: post meta was not set, so go with the global setting.
529 if ( '' === $post_likes_switched ) {
530 return $sitewide_likes_enabled;
531 } elseif ( '0' === $post_likes_switched ) { // User overrode the global setting to disable likes.
532 return false;
533 } elseif ( '1' === $post_likes_switched ) { // User overrode the global setting to enable likes.
534 return true;
535 }
536 // No default fallback, let's stay explicit.
537 }
538
539 /**
540 * Callback to set switch_like_status post_meta when jetpack_likes_enabled is updated.
541 *
542 * Warning: this behavior is somewhat complicated!
543 * When the switch_like_status post_meta is unset, we follow the global setting in Sharing.
544 * When it is set to 0, we disable likes on the post, regardless of the global setting.
545 * When it is set to 1, we enable likes on the post, regardless of the global setting.
546 *
547 * @param bool $enable_post_likes - checks if post likes are enabled.
548 * @param object $post_object - object containing post data.
549 */
550 function jetpack_post_likes_update_value( $enable_post_likes, $post_object ) {
551 /** This filter is documented in modules/jetpack-likes-settings.php */
552 $sitewide_likes_enabled = (bool) apply_filters( 'wpl_is_enabled_sitewide', ! get_option( 'disabled_likes' ) );
553
554 $should_switch_status = $enable_post_likes !== $sitewide_likes_enabled;
555
556 if ( $should_switch_status ) {
557 // Set the meta to 0 if the user wants to disable likes, 1 if user wants to enable.
558 $switch_like_status = ( $enable_post_likes ? 1 : 0 );
559 return update_post_meta( $post_object->ID, 'switch_like_status', $switch_like_status );
560 } else {
561 // Unset the meta otherwise.
562 return delete_post_meta( $post_object->ID, 'switch_like_status' );
563 }
564 }
565
566 /**
567 * Add Likes post_meta to the REST API Post response.
568 *
569 * @action rest_api_init
570 * @uses register_rest_field
571 * @link https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
572 */
573 function jetpack_post_likes_register_rest_field() {
574 $post_types = get_post_types( array( 'public' => true ) );
575 foreach ( $post_types as $post_type ) {
576 register_rest_field(
577 $post_type,
578 'jetpack_likes_enabled',
579 array(
580 'get_callback' => 'jetpack_post_likes_get_value',
581 'update_callback' => 'jetpack_post_likes_update_value',
582 'schema' => array(
583 'description' => __( 'Are Likes enabled?', 'jetpack' ),
584 'type' => 'boolean',
585 ),
586 )
587 );
588
589 /**
590 * Ensures all public internal post-types support `likes`
591 * This feature support flag is used by the REST API and Gutenberg.
592 */
593 add_post_type_support( $post_type, 'jetpack-post-likes' );
594 }
595 }
596
597 // Add Likes post_meta to the REST API Post response.
598 add_action( 'rest_api_init', 'jetpack_post_likes_register_rest_field' );
599
600 // Some CPTs (e.g. Jetpack portfolios and testimonials) get registered with
601 // restapi_theme_init because they depend on theme support, so let's also hook to that.
602 add_action( 'restapi_theme_init', 'jetpack_post_likes_register_rest_field', 20 );
603
604 /**
605 * Set the Likes and Sharing Gutenberg extension availability.
606 */
607 function jetpack_post_likes_set_extension_availability() {
608 Jetpack_Gutenberg::set_extension_available( 'likes' );
609 }
610
611 add_action( 'jetpack_register_gutenberg_extensions', 'jetpack_post_likes_set_extension_availability' );
612
613 Jetpack_Likes::init();
614