PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3 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 All 508 releases
← All changes | modules/likes.php +106 -33 16.3-beta → 16.3-a.1 View file →
@@ -20,9 +20,8 @@
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\Sharing_Likes\Post_Likes_Switch;
25 24 use Automattic\Jetpack\Status\Host;
26 25
27 26 if ( ! defined( 'ABSPATH' ) ) {
28 27 exit( 0 );
@@ -102,12 +101,30 @@
102 101 Jetpack::enable_module_configurable( __FILE__ );
103 102 }
104 103
105 104 add_filter( 'jetpack_module_configuration_url_likes', array( $this, 'jetpack_likes_configuration_url' ) );
105 + add_action( 'admin_print_scripts-settings_page_sharing', array( $this, 'load_jp_css' ) );
106 + add_filter( 'sharing_show_buttons_on_row_start', array( $this, 'configuration_target_area' ) );
106 107
108 + $publicize_active = Jetpack::is_module_active( 'publicize' );
107 109 $sharedaddy_active = Jetpack::is_module_active( 'sharedaddy' );
108 110
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 ) {
118 + // we have a sharing page but not the global options area.
119 + add_action( 'pre_admin_screen_sharing', array( $this->settings, 'sharing_block' ), 20 );
120 + add_action( 'pre_admin_screen_sharing', array( $this->settings, 'updated_message' ), -10 );
121 + }
122 +
109 123 if ( ! $sharedaddy_active ) {
124 + add_action( 'admin_init', array( $this->settings, 'process_update_requests_if_sharedaddy_not_loaded' ) );
125 + add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_showbuttonon_init' ), 19 );
126 + add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_showbuttonon_callback' ), 19 );
110 127 add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) );
111 128 } else {
112 129 add_filter( 'sharing_meta_box_title', array( $this->settings, 'add_likes_to_sharing_meta_box_title' ) );
113 130 add_action( 'start_sharing_meta_box_content', array( $this->settings, 'meta_box_content' ) );
@@ -118,8 +135,10 @@
118 135 add_action( 'wp_enqueue_scripts', array( $this, 'load_styles_register_scripts' ) );
119 136
120 137 add_action( 'save_post', array( $this->settings, 'meta_box_save' ) );
121 138 add_action( 'edit_attachment', array( $this->settings, 'meta_box_save' ) );
139 + add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_init' ), 20 );
140 + add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_callback' ), 20 );
122 141 }
123 142
124 143 /**
125 144 * Set the social_notifications_like option to `on` when the Likes module is activated.
@@ -150,31 +169,17 @@
150 169 }
151 170
152 171 /**
153 172 * Loads Jetpack's CSS on the sharing page so we can use .jetpack-targetable
154 - *
155 - * @deprecated 16.3 Settings > Sharing is a plain WordPress settings screen now.
156 - *
157 - * @return void
158 173 */
159 174 public function load_jp_css() {
160 - _deprecated_function( __METHOD__, 'jetpack-16.3' );
175 + /**
176 + * Do we really need `admin_styles`? With the new admin UI, it's breaking some bits.
177 + * Jetpack::init()->admin_styles();
178 + */
161 179 }
162 180
163 181 /**
164 - * Adds in the jetpack-targetable class so when we visit sharing#likes our like settings get highlighted by a yellow box
165 - *
166 - * @deprecated 16.3 The Likes settings have a section of their own on Settings > Sharing.
167 - *
168 - * @param string $html row heading for the sharedaddy "which page" setting.
169 - * @return string The unchanged $html.
170 - */
171 - public function configuration_target_area( $html = '' ) {
172 - _deprecated_function( __METHOD__, 'jetpack-16.3' );
173 - return $html;
174 - }
175 -
176 - /**
177 182 * Load scripts and styles for front end.
178 183 */
179 184 public function load_styles_register_scripts() {
180 185 // Likes are only rendered on pages that display post content.
@@ -206,10 +211,21 @@
206 211 );
207 212 }
208 213
209 214 /**
210 - * Options to be added to the discussion page. The Sharing settings live in Sharing_Likes\Settings\Likes_Section.
215 + * Adds in the jetpack-targetable class so when we visit sharing#likes our like settings get highlighted by a yellow box
216 + *
217 + * @param string $html row heading for the sharedaddy "which page" setting.
218 + * @return string $html with the jetpack-targetable class and likes id. tbody gets closed after the like settings
211 219 */
220 + public function configuration_target_area( $html = '' ) {
221 + $html = "<tbody id='likes' class='jetpack-targetable'>" . $html;
222 + return $html;
223 + }
224 +
225 + /**
226 + * Options to be added to the discussion page (see also admin_settings_init, etc below for Sharing settings page)
227 + */
212 228 public function admin_discussion_likes_settings_init() {
213 229 // Add a temporary section, until we can move the setting out of there and with the rest of the email notification settings.
214 230 add_settings_section( 'likes-notifications', __( 'Likes Notifications', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_section' ), 'discussion' );
215 231 add_settings_field( 'social-notifications', __( 'Email me whenever', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_field' ), 'discussion', 'likes-notifications' );
@@ -491,43 +507,100 @@
491 507
492 508 /**
493 509 * Callback to get the value for the jetpack_likes_enabled field.
494 510 *
495 - * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Post_Likes_Switch::get_value() instead.
511 + * Warning: this behavior is somewhat complicated!
512 + * When the switch_like_status post_meta is unset, we follow the global setting in Sharing.
513 + * When it is set to 0, we disable likes on the post, regardless of the global setting.
514 + * When it is set to 1, we enable likes on the post, regardless of the global setting.
496 515 *
497 516 * @param array $post - post data we're checking.
498 517 *
499 - * @return bool|null
518 + * @return bool
500 519 */
501 520 function jetpack_post_likes_get_value( array $post ) {
502 - _deprecated_function( __FUNCTION__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Post_Likes_Switch::get_value' );
503 - return Post_Likes_Switch::get_value( $post );
521 + if ( ! isset( $post['id'] ) ) {
522 + return false;
523 + }
524 +
525 + $post_likes_switched = get_post_meta( $post['id'], 'switch_like_status', true );
526 +
527 + /** This filter is documented in modules/jetpack-likes-settings.php */
528 + $sitewide_likes_enabled = (bool) apply_filters( 'wpl_is_enabled_sitewide', ! get_option( 'disabled_likes' ) );
529 +
530 + // An empty string: post meta was not set, so go with the global setting.
531 + if ( '' === $post_likes_switched ) {
532 + return $sitewide_likes_enabled;
533 + } elseif ( '0' === $post_likes_switched ) { // User overrode the global setting to disable likes.
534 + return false;
535 + } elseif ( '1' === $post_likes_switched ) { // User overrode the global setting to enable likes.
536 + return true;
537 + }
538 + // No default fallback, let's stay explicit.
504 539 }
505 540
506 541 /**
507 542 * Callback to set switch_like_status post_meta when jetpack_likes_enabled is updated.
508 543 *
509 - * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Post_Likes_Switch::update_value() instead.
544 + * Warning: this behavior is somewhat complicated!
545 + * When the switch_like_status post_meta is unset, we follow the global setting in Sharing.
546 + * When it is set to 0, we disable likes on the post, regardless of the global setting.
547 + * When it is set to 1, we enable likes on the post, regardless of the global setting.
510 548 *
511 549 * @param bool $enable_post_likes - checks if post likes are enabled.
512 550 * @param object $post_object - object containing post data.
513 - *
514 - * @return int|bool
515 551 */
516 552 function jetpack_post_likes_update_value( $enable_post_likes, $post_object ) {
517 - _deprecated_function( __FUNCTION__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Post_Likes_Switch::update_value' );
518 - return Post_Likes_Switch::update_value( $enable_post_likes, $post_object );
553 + /** This filter is documented in modules/jetpack-likes-settings.php */
554 + $sitewide_likes_enabled = (bool) apply_filters( 'wpl_is_enabled_sitewide', ! get_option( 'disabled_likes' ) );
555 +
556 + $should_switch_status = $enable_post_likes !== $sitewide_likes_enabled;
557 +
558 + if ( $should_switch_status ) {
559 + // Set the meta to 0 if the user wants to disable likes, 1 if user wants to enable.
560 + $switch_like_status = ( $enable_post_likes ? 1 : 0 );
561 + return update_post_meta( $post_object->ID, 'switch_like_status', $switch_like_status );
562 + } else {
563 + // Unset the meta otherwise.
564 + return delete_post_meta( $post_object->ID, 'switch_like_status' );
565 + }
519 566 }
520 567
521 568 /**
522 569 * Add Likes post_meta to the REST API Post response.
523 570 *
524 - * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Post_Likes_Switch::register_rest_field() instead.
571 + * @action rest_api_init
572 + * @uses register_rest_field
573 + * @link https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
525 574 */
526 575 function jetpack_post_likes_register_rest_field() {
527 - _deprecated_function( __FUNCTION__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Post_Likes_Switch::register_rest_field' );
528 - Post_Likes_Switch::register_rest_field();
576 + $post_types = get_post_types( array( 'public' => true ) );
577 + foreach ( $post_types as $post_type ) {
578 + register_rest_field(
579 + $post_type,
580 + 'jetpack_likes_enabled',
581 + array(
582 + 'get_callback' => 'jetpack_post_likes_get_value',
583 + 'update_callback' => 'jetpack_post_likes_update_value',
584 + 'schema' => array(
585 + 'description' => __( 'Are Likes enabled?', 'jetpack' ),
586 + 'type' => 'boolean',
587 + ),
588 + )
589 + );
590 +
591 + /**
592 + * Ensures all public internal post-types support `likes`
593 + * This feature support flag is used by the REST API and Gutenberg.
594 + */
595 + add_post_type_support( $post_type, 'jetpack-post-likes' );
596 + }
529 597 }
530 598
531 -Post_Likes_Switch::init();
599 +// Add Likes post_meta to the REST API Post response.
600 +add_action( 'rest_api_init', 'jetpack_post_likes_register_rest_field' );
601 +
602 +// Some CPTs (e.g. Jetpack portfolios and testimonials) get registered with
603 +// restapi_theme_init because they depend on theme support, so let's also hook to that.
604 +add_action( 'restapi_theme_init', 'jetpack_post_likes_register_rest_field', 20 );
532 605
533 606 Jetpack_Likes::init();