PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
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 13.8.3 All 506 releases
← All changes | modules/likes/jetpack-likes-settings.php +116 -241 12.2.3 → 16.3-a.7 View file →
@@ -1,6 +1,7 @@
1 1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 2
3 +use Automattic\Jetpack\Status\Host;
3 4 use Automattic\Jetpack\Sync\Settings;
4 5
5 6 /**
6 7 * Jetpack likes settings class.
@@ -7,19 +8,19 @@
7 8 */
8 9 class Jetpack_Likes_Settings {
9 10
10 11 /**
11 - * False if running on WPCOM Simple
12 + * Determines whether the module runs in the Jetpack plugin, as opposed to WP.com Simple site environment
12 13 *
13 14 * @var bool
14 15 */
15 - public $in_jetpack;
16 + public $in_jetpack = true;
16 17
17 18 /**
18 19 * Constructor function.
19 20 */
20 21 public function __construct() {
21 - $this->in_jetpack = ! ( defined( 'IS_WPCOM' ) && IS_WPCOM );
22 + $this->in_jetpack = ! ( new Host() )->is_wpcom_simple();
22 23 }
23 24
24 25 /**
25 26 * Replaces the "Sharing" title for the post screen metabox with "Likes and Shares"
@@ -96,9 +97,9 @@
96 97 <?php esc_html_e( 'Show likes.', 'jetpack' ); ?>
97 98 </label>
98 99 <input type="hidden" name="wpl_like_status_hidden" value="1" />
99 100 <?php wp_nonce_field( 'likes-and-shares', '_likesharenonce' ); ?>
100 - </p>
101 + </p>
101 102 <?php
102 103 /**
103 104 * Fires after the Likes meta box content in the post editor.
104 105 *
@@ -139,9 +140,9 @@
139 140 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
140 141 return $post_id;
141 142 }
142 143
143 - if ( empty( $_POST['wpl_like_status_hidden'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- we're not changing anything on the site.
144 + if ( empty( $_POST['wpl_like_status_hidden'] ) ) {
144 145 return $post_id;
145 146 }
146 147
147 148 if ( ! isset( $_POST['_likesharenonce'] ) || ! wp_verify_nonce( $_POST['_likesharenonce'], 'likes-and-shares' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- WordPress core doesn't unslash or verify nonces either.
@@ -200,71 +201,67 @@
200 201 <input type="checkbox" name="wpl_enable_post_sharing" id="wpl_enable_post_sharing" value="1" <?php checked( ! $disabled ); ?>>
201 202 <?php esc_html_e( 'Show sharing buttons.', 'jetpack' ); ?>
202 203 </label>
203 204 <input type="hidden" name="wpl_sharing_status_hidden" value="1" />
204 - </p>
205 + </p>
205 206 <?php
206 207 }
207 208
208 209 /**
210 + * Should we register the Settings > Sharing screen ourselves?
211 + *
212 + * @deprecated 16.3 Settings > Sharing is registered by Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page.
213 + *
214 + * @param bool $sharedaddy_active Whether the Sharing (sharedaddy) module is active.
215 + * @return bool
216 + */
217 + public function needs_own_sharing_menu( $sharedaddy_active ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
218 + _deprecated_function( __METHOD__, 'jetpack-16.3' );
219 + return false;
220 + }
221 +
222 + /**
209 223 * Adds the 'sharing' menu to the settings menu.
210 - * Only ran if sharedaddy and publicize are not already active.
224 + *
225 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::register_menu() instead.
226 + *
227 + * @return void
211 228 */
212 229 public function sharing_menu() {
213 - add_submenu_page( 'options-general.php', esc_html__( 'Sharing Settings', 'jetpack' ), esc_html__( 'Sharing', 'jetpack' ), 'manage_options', 'sharing', array( $this, 'sharing_page' ) );
230 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::register_menu' );
214 231 }
215 232
216 233 /**
217 - * Provides a sharing page with the sharing_global_options hook
218 - * so we can display the setting.
219 - * Only ran if sharedaddy and publicize are not already active.
234 + * Provides a sharing page with the sharing_global_options hook so we can display the setting.
235 + *
236 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render() instead.
237 + *
238 + * @return void
220 239 */
221 240 public function sharing_page() {
222 - $this->updated_message();
223 - ?>
224 - <div class="wrap">
225 - <div class="icon32" id="icon-options-general"><br /></div>
226 - <h1><?php esc_html_e( 'Sharing Settings', 'jetpack' ); ?></h1>
227 - <?php
228 - /** This action is documented in modules/sharedaddy/sharing.php */
229 - do_action( 'pre_admin_screen_sharing' );
230 - ?>
231 - <?php $this->sharing_block(); ?>
232 - </div>
233 - <?php
241 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render' );
234 242 }
235 243
236 244 /**
237 245 * Returns the settings have been saved message.
246 + *
247 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render() instead.
248 + *
249 + * @return void
238 250 */
239 251 public function updated_message() {
240 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- ignoring since we are just displaying that the settings have been saved and not making any other changes to the site.
241 - if ( isset( $_GET['update'] ) && 'saved' === $_GET['update'] ) {
242 - echo '<div class="updated"><p>' . esc_html__( 'Settings have been saved', 'jetpack' ) . '</p></div>';
243 - }
252 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render' );
244 253 }
245 254
246 255 /**
247 - * Returns just the "sharing buttons" w/ like option block, so it can be inserted into different sharing page contexts
256 + * Returns the Likes options block, so it can be inserted into different sharing page contexts.
257 + *
258 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Likes_Section::render() instead.
259 + *
260 + * @return void
248 261 */
249 262 public function sharing_block() {
250 - ?>
251 - <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2>
252 - <form method="post" action="">
253 - <table class="form-table">
254 - <tbody>
255 - <?php
256 - /** This action is documented in modules/sharedaddy/sharing.php */
257 - do_action( 'sharing_global_options' );
258 - ?>
259 - </tbody>
260 - </table>
261 -
262 - <p class="submit">
263 - <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" />
264 - <?php wp_nonce_field( 'sharing-options' ); ?>
265 - </form>
266 - <?php
263 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Likes_Section::render' );
267 264 }
268 265
269 266 /**
270 267 * Are likes enabled for this post?
@@ -277,8 +274,12 @@
277 274 if ( ! $post || is_wp_error( $post ) ) {
278 275 return false;
279 276 }
280 277
278 + if ( ! empty( $post->post_password ) ) {
279 + return false;
280 + }
281 +
281 282 $sitewide_likes_enabled = (bool) $this->is_enabled_sitewide();
282 283 $post_likes_switched = get_post_meta( $post->ID, 'switch_like_status', true );
283 284
284 285 /*
@@ -431,9 +432,9 @@
431 432 * @return bool
432 433 */
433 434 public function is_single_post_enabled( $post_type = 'post' ) {
434 435 $options = $this->get_options();
435 - return (bool) apply_filters(
436 +
436 437 /**
437 438 * Filters whether Likes should be enabled on single posts.
438 439 *
439 440 * The dynamic part of the filter, {$post_type}, allows you to specific the post type where Likes should be enabled.
@@ -443,11 +444,14 @@
443 444 * @since 2.2.0
444 445 *
445 446 * @param bool $enabled Are Post Likes enabled on single posts?
446 447 */
448 + $post_likes_enabled = apply_filters(
447 449 "wpl_is_single_{$post_type}_disabled",
448 - (bool) in_array( $post_type, $options['show'], true )
450 + in_array( $post_type, $options['show'], true )
449 451 );
452 +
453 + return (bool) $post_likes_enabled;
450 454 }
451 455
452 456 /**
453 457 * Get the 'disabled_likes' option from the DB of the current blog.
@@ -458,12 +462,45 @@
458 462 $setting = array();
459 463 $setting['disabled'] = get_option( 'disabled_likes' );
460 464 $sharing = get_option( 'sharing-options', array() );
461 465
466 + if ( ! is_array( $sharing ) ) {
467 + $sharing = array();
468 + }
469 + if ( ! isset( $sharing['global'] ) || ! is_array( $sharing['global'] ) ) {
470 + $sharing['global'] = array();
471 + }
472 +
462 473 // Default visibility settings
463 474 if ( ! isset( $sharing['global']['show'] ) ) {
464 - $sharing['global']['show'] = array( 'post', 'page' );
475 + $public_commentable_cpts = array_filter(
476 + get_post_types(
477 + array(
478 + 'public' => true,
479 + '_builtin' => false,
480 + )
481 + ),
482 + function ( $post_type ) {
483 + return post_type_supports( $post_type, 'comments' );
484 + }
485 + );
486 + $public_commentable_cpts = array_values( $public_commentable_cpts );
465 487
488 + /**
489 + * Filters the default post types that show Likes when no sharing settings have been saved.
490 + *
491 + * Only applies when the site has never explicitly configured Likes visibility.
492 + * Once a site owner saves sharing settings, those are used instead.
493 + *
494 + * @since 16.2
495 + *
496 + * @param string[] $post_types Array of post type slugs that will show Likes by default.
497 + */
498 + $sharing['global']['show'] = apply_filters(
499 + 'jetpack_likes_default_post_types',
500 + array_merge( array( 'post', 'page' ), $public_commentable_cpts )
501 + );
502 +
466 503 // Scalar check
467 504 } elseif ( is_scalar( $sharing['global']['show'] ) ) {
468 505 switch ( $sharing['global']['show'] ) {
469 506 case 'posts':
@@ -477,10 +514,11 @@
477 514 break;
478 515 }
479 516 }
480 517
481 - // Ensure it's always an array (even if not previously empty or scalar)
482 - $setting['show'] = ! empty( $sharing['global']['show'] ) ? (array) $sharing['global']['show'] : array();
518 + // Ensure it's always an array (even if not previously empty or scalar).
519 + $show = $sharing['global']['show'] ?? array();
520 + $setting['show'] = ! empty( $show ) ? (array) $show : array();
483 521
484 522 /**
485 523 * Filters where the Likes are displayed.
486 524 *
@@ -508,9 +546,9 @@
508 546 * @since 2.2.0
509 547 *
510 548 * @param bool $enabled Are Post Likes enabled on archive/front/search pages?
511 549 */
512 - return (bool) apply_filters( 'wpl_is_index_disabled', (bool) in_array( 'index', $options['show'], true ) );
550 + return (bool) apply_filters( 'wpl_is_index_disabled', in_array( 'index', $options['show'], true ) );
513 551 }
514 552
515 553 /**
516 554 * Are Post Likes enabled on single pages?
@@ -527,9 +565,9 @@
527 565 * @since 2.2.0
528 566 *
529 567 * @param bool $enabled Are Post Likes enabled on single pages?
530 568 */
531 - return (bool) apply_filters( 'wpl_is_single_page_disabled', (bool) in_array( 'page', $options['show'], true ) );
569 + return (bool) apply_filters( 'wpl_is_single_page_disabled', in_array( 'page', $options['show'], true ) );
532 570 }
533 571
534 572 /**
535 573 * Are Media Likes enabled on single pages?
@@ -546,74 +584,20 @@
546 584 * @since 2.2.0
547 585 *
548 586 * @param bool $enabled Are Post Likes enabled on attachment pages?
549 587 */
550 - return (bool) apply_filters( 'wpl_is_attachment_disabled', (bool) in_array( 'attachment', $options['show'], true ) );
588 + return (bool) apply_filters( 'wpl_is_attachment_disabled', in_array( 'attachment', $options['show'], true ) );
551 589 }
552 590
553 591 /**
554 592 * The actual options block to be inserted into the sharing page.
593 + *
594 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Likes_Section::render() instead.
595 + *
596 + * @return void
555 597 */
556 598 public function admin_settings_init() {
557 - ?>
558 - <tr>
559 - <th scope="row">
560 - <label><?php esc_html_e( 'WordPress.com Likes are', 'jetpack' ); ?></label>
561 - </th>
562 - <td>
563 - <div>
564 - <label>
565 - <input type="radio" class="code" name="wpl_default" value="on" <?php checked( $this->is_enabled_sitewide(), true ); ?> />
566 - <?php esc_html_e( 'On for all posts', 'jetpack' ); ?>
567 - </label>
568 - </div>
569 - <div>
570 - <label>
571 - <input type="radio" class="code" name="wpl_default" value="off" <?php checked( $this->is_enabled_sitewide(), false ); ?> />
572 - <?php esc_html_e( 'Turned on per post', 'jetpack' ); ?>
573 - </label>
574 - <div>
575 - </td>
576 - </tr>
577 - <?php if ( ! $this->in_jetpack ) : ?>
578 - <tr>
579 - <th scope="row">
580 - <label><?php esc_html_e( 'WordPress.com Reblog Button', 'jetpack' ); ?></label>
581 - </th>
582 - <td>
583 - <div>
584 - <label>
585 - <input type="radio" class="code" name="jetpack_reblogs_enabled" value="on" <?php checked( $this->reblogs_enabled_sitewide(), true ); ?> />
586 - <?php esc_html_e( 'Show the Reblog button on posts', 'jetpack' ); ?>
587 - </label>
588 - </div>
589 - <div>
590 - <label>
591 - <input type="radio" class="code" name="jetpack_reblogs_enabled" value="off" <?php checked( $this->reblogs_enabled_sitewide(), false ); ?> />
592 - <?php esc_html_e( 'Don\'t show the Reblog button on posts', 'jetpack' ); ?>
593 - </label>
594 - </div>
595 - </td>
596 - </tr>
597 - <!-- WPCOM only: Comment Likes -->
598 - <?php if ( ! $this->in_jetpack ) : ?>
599 - <tr>
600 - <th scope="row">
601 - <label><?php esc_html_e( 'Comment Likes are', 'jetpack' ); ?></label>
602 - </th>
603 - <td>
604 - <div>
605 - <label>
606 - <input type="checkbox" class="code" name="jetpack_comment_likes_enabled" value="1" <?php checked( $this->is_comments_enabled(), true ); ?> />
607 - <?php esc_html_e( 'On for all comments', 'jetpack' ); ?>
608 - </label>
609 - </div>
610 - </td>
611 - </tr>
612 - <?php endif; ?>
613 - <?php endif; ?>
614 - </tbody> <?php // closes the tbody attached to sharing_show_buttons_on_row_start... ?>
615 - <?php
599 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Likes_Section::render' );
616 600 }
617 601
618 602 /**
619 603 * Returns the current state of the "WordPress.com Reblogs are" option.
@@ -655,155 +639,46 @@
655 639 }
656 640
657 641 /**
658 642 * Saves the setting in the database.
643 + *
644 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle() instead.
645 + *
646 + * @return void
659 647 */
660 648 public function admin_settings_callback() {
661 - if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- WordPress core doesn't unslash or verify nonces either.
662 - return;
663 - }
664 -
665 - // We're looking for these, and doing a dance to set some stats and save
666 - // them together in array option.
667 - if ( ! empty( $_POST['wpl_default'] ) ) {
668 - $new_state = sanitize_text_field( wp_unslash( $_POST['wpl_default'] ) );
669 - } else {
670 - $new_state = 'on';
671 - }
672 -
673 - if ( ! empty( $_POST['jetpack_reblogs_enabled'] ) ) {
674 - $reblogs_new_state = sanitize_text_field( wp_unslash( $_POST['jetpack_reblogs_enabled'] ) );
675 - } else {
676 - $reblogs_new_state = 'on';
677 - }
678 -
679 - // Checked (enabled)
680 - switch ( $new_state ) {
681 - case 'off':
682 - update_option( 'disabled_likes', 1 );
683 - break;
684 - case 'on':
685 - default:
686 - delete_option( 'disabled_likes' );
687 - break;
688 - }
689 -
690 - switch ( $reblogs_new_state ) {
691 - case 'off':
692 - update_option( 'disabled_reblogs', 1 );
693 - break;
694 - case 'on':
695 - default:
696 - delete_option( 'disabled_reblogs' );
697 - break;
698 - }
699 -
700 - // WPCOM only: Comment Likes
701 - if ( ! $this->in_jetpack ) {
702 - if ( ! empty( $_POST['jetpack_comment_likes_enabled'] ) ) {
703 - $new_comments_state = sanitize_text_field( wp_unslash( $_POST['jetpack_comment_likes_enabled'] ) );
704 - } else {
705 - $new_comments_state = false;
706 - }
707 - switch ( (bool) $new_comments_state ) {
708 - case true:
709 - update_option( 'jetpack_comment_likes_enabled', 1 );
710 - break;
711 - case false:
712 - default:
713 - update_option( 'jetpack_comment_likes_enabled', 0 );
714 - break;
715 - }
716 - }
649 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle' );
717 650 }
718 651
719 652 /**
720 653 * Adds the admin update hook so we can save settings even if Sharedaddy is not enabled.
654 + *
655 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle() instead.
656 + *
657 + * @return void
721 658 */
722 659 public function process_update_requests_if_sharedaddy_not_loaded() {
723 - if ( isset( $_GET['page'] ) && ( $_GET['page'] === 'sharing.php' || $_GET['page'] === 'sharing' ) ) {
724 - if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- WordPress core doesn't unslash or verify nonces either.
725 - /** This action is documented in modules/sharedaddy/sharing.php */
726 - do_action( 'sharing_admin_update' );
727 - wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) );
728 - die();
729 - }
730 - }
660 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle' );
731 661 }
732 662
733 663 /**
734 664 * If sharedaddy is not loaded, we don't have the "Show buttons on" yet, so we need to add that since it affects likes too.
665 + *
666 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Placement_Section::render() instead.
667 + *
668 + * @return void
735 669 */
736 670 public function admin_settings_showbuttonon_init() {
737 - /** This action is documented in modules/sharedaddy/sharing.php */
738 - echo apply_filters( 'sharing_show_buttons_on_row_start', '<tr valign="top">' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
739 - ?>
740 - <th scope="row"><label><?php esc_html_e( 'Show buttons on', 'jetpack' ); ?></label></th>
741 - <td>
742 - <?php
743 - $br = false;
744 - $shows = array_values( get_post_types( array( 'public' => true ) ) );
745 - array_unshift( $shows, 'index' );
746 - $global = $this->get_options();
747 - foreach ( $shows as $show ) :
748 - if ( 'index' === $show ) {
749 - $label = __( 'Front Page, Archive Pages, and Search Results', 'jetpack' );
750 - } else {
751 - $post_type_object = get_post_type_object( $show );
752 - $label = $post_type_object->labels->name;
753 - }
754 -
755 - if ( $br ) {
756 - echo '<br />';
757 - }
758 - ?>
759 - <label><input type="checkbox"<?php checked( in_array( $show, $global['show'], true ) ); ?> name="show[]" value="<?php echo esc_attr( $show ); ?>" /> <?php echo esc_html( $label ); ?></label>
760 - <?php
761 - $br = true;
762 - endforeach;
763 - ?>
764 - </td>
765 - <?php
766 - /** This action is documented in modules/sharedaddy/sharing.php */
767 - echo apply_filters( 'sharing_show_buttons_on_row_end', '</tr>' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
671 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Placement_Section::render' );
768 672 }
769 673
770 674 /**
771 675 * If sharedaddy is not loaded, we still need to save the the settings of the "Show buttons on" option.
676 + *
677 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle() instead.
678 + *
679 + * @return void
772 680 */
773 681 public function admin_settings_showbuttonon_callback() {
774 - $options = get_option( 'sharing-options' );
775 - if ( ! is_array( $options ) ) {
776 - $options = array();
777 - }
778 -
779 - $shows = array_values( get_post_types( array( 'public' => true ) ) );
780 - $shows[] = 'index';
781 - // phpcs:ignore WordPress.Security.NonceVerification.Missing -- triggered due to the 'sharing_admin_update' action, but the code in sharing.php checks for the nonce before firing the action.
782 - $data = $_POST;
783 -
784 - if ( isset( $data['show'] ) ) {
785 - if ( is_scalar( $data['show'] ) ) {
786 - switch ( $data['show'] ) {
787 - case 'posts':
788 - $data['show'] = array( 'post', 'page' );
789 - break;
790 - case 'index':
791 - $data['show'] = array( 'index' );
792 - break;
793 - case 'posts-index':
794 - $data['show'] = array( 'post', 'page', 'index' );
795 - break;
796 - }
797 - }
798 -
799 - $data['show'] = array_intersect( $data['show'], $shows );
800 - if ( $data['show'] ) {
801 - $options['global']['show'] = $data['show'];
802 - }
803 - } else {
804 - $options['global']['show'] = array();
805 - }
806 -
807 - update_option( 'sharing-options', $options );
682 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle' );
808 683 }
809 684 }