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/likes.php +33 -106 16.3-a.3 → 16.3-beta View file →
@@ -20,8 +20,9 @@
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;
24 25 use Automattic\Jetpack\Status\Host;
25 26
26 27 if ( ! defined( 'ABSPATH' ) ) {
27 28 exit( 0 );
@@ -101,30 +102,12 @@
101 102 Jetpack::enable_module_configurable( __FILE__ );
102 103 }
103 104
104 105 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' ) );
107 106
108 - $publicize_active = Jetpack::is_module_active( 'publicize' );
109 107 $sharedaddy_active = Jetpack::is_module_active( 'sharedaddy' );
110 108
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 -
123 109 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 );
127 110 add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) );
128 111 } else {
129 112 add_filter( 'sharing_meta_box_title', array( $this->settings, 'add_likes_to_sharing_meta_box_title' ) );
130 113 add_action( 'start_sharing_meta_box_content', array( $this->settings, 'meta_box_content' ) );
@@ -135,10 +118,8 @@
135 118 add_action( 'wp_enqueue_scripts', array( $this, 'load_styles_register_scripts' ) );
136 119
137 120 add_action( 'save_post', array( $this->settings, 'meta_box_save' ) );
138 121 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 );
141 122 }
142 123
143 124 /**
144 125 * Set the social_notifications_like option to `on` when the Likes module is activated.
@@ -169,17 +150,31 @@
169 150 }
170 151
171 152 /**
172 153 * 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
173 158 */
174 159 public function load_jp_css() {
175 - /**
176 - * Do we really need `admin_styles`? With the new admin UI, it's breaking some bits.
177 - * Jetpack::init()->admin_styles();
178 - */
160 + _deprecated_function( __METHOD__, 'jetpack-16.3' );
179 161 }
180 162
181 163 /**
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 + /**
182 177 * Load scripts and styles for front end.
183 178 */
184 179 public function load_styles_register_scripts() {
185 180 // Likes are only rendered on pages that display post content.
@@ -211,21 +206,10 @@
211 206 );
212 207 }
213 208
214 209 /**
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
210 + * Options to be added to the discussion page. The Sharing settings live in Sharing_Likes\Settings\Likes_Section.
219 211 */
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 - */
228 212 public function admin_discussion_likes_settings_init() {
229 213 // Add a temporary section, until we can move the setting out of there and with the rest of the email notification settings.
230 214 add_settings_section( 'likes-notifications', __( 'Likes Notifications', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_section' ), 'discussion' );
231 215 add_settings_field( 'social-notifications', __( 'Email me whenever', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_field' ), 'discussion', 'likes-notifications' );
@@ -507,100 +491,43 @@
507 491
508 492 /**
509 493 * Callback to get the value for the jetpack_likes_enabled field.
510 494 *
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.
495 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Post_Likes_Switch::get_value() instead.
515 496 *
516 497 * @param array $post - post data we're checking.
517 498 *
518 - * @return bool
499 + * @return bool|null
519 500 */
520 501 function jetpack_post_likes_get_value( array $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.
502 + _deprecated_function( __FUNCTION__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Post_Likes_Switch::get_value' );
503 + return Post_Likes_Switch::get_value( $post );
539 504 }
540 505
541 506 /**
542 507 * Callback to set switch_like_status post_meta when jetpack_likes_enabled is updated.
543 508 *
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.
509 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Post_Likes_Switch::update_value() instead.
548 510 *
549 511 * @param bool $enable_post_likes - checks if post likes are enabled.
550 512 * @param object $post_object - object containing post data.
513 + *
514 + * @return int|bool
551 515 */
552 516 function jetpack_post_likes_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 - }
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 );
566 519 }
567 520
568 521 /**
569 522 * Add Likes post_meta to the REST API Post response.
570 523 *
571 - * @action rest_api_init
572 - * @uses register_rest_field
573 - * @link https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
524 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Post_Likes_Switch::register_rest_field() instead.
574 525 */
575 526 function jetpack_post_likes_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 - }
527 + _deprecated_function( __FUNCTION__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Post_Likes_Switch::register_rest_field' );
528 + Post_Likes_Switch::register_rest_field();
597 529 }
598 530
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 );
531 +Post_Likes_Switch::init();
605 532
606 533 Jetpack_Likes::init();