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/jetpack-likes-settings.php +86 -28 13.7.216.3-a.1 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,17 +201,34 @@
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 + * Our settings are displayed on Settings > Sharing, but that screen is registered by
213 + * the Sharing (sharedaddy) module. When that module is off, nothing registers the
214 + * screen and our settings become unreachable.
215 + *
216 + * WordPress.com Simple sites are excluded: the screen is registered elsewhere there.
217 + *
218 + * @since 16.2
219 + *
220 + * @param bool $sharedaddy_active Whether the Sharing (sharedaddy) module is active.
221 + * @return bool
222 + */
223 + public function needs_own_sharing_menu( $sharedaddy_active ) {
224 + return ! $sharedaddy_active && $this->in_jetpack;
225 + }
226 +
227 + /**
209 228 * Adds the 'sharing' menu to the settings menu.
210 - * Only ran if sharedaddy and publicize are not already active.
211 - *
212 - * @deprecated 13.2
229 + * Only ran when the Sharing (sharedaddy) module is inactive on a Jetpack site,
230 + * since Settings > Sharing is where our settings live. See needs_own_sharing_menu().
213 231 */
214 232 public function sharing_menu() {
215 233 add_submenu_page( 'options-general.php', esc_html__( 'Sharing Settings', 'jetpack' ), esc_html__( 'Sharing', 'jetpack' ), 'manage_options', 'sharing', array( $this, 'sharing_page' ) );
216 234 }
@@ -217,11 +235,10 @@
217 235
218 236 /**
219 237 * Provides a sharing page with the sharing_global_options hook
220 238 * so we can display the setting.
221 - * Only ran if sharedaddy and publicize are not already active.
222 - *
223 - * @deprecated 13.2
239 + * Only ran when the Sharing (sharedaddy) module is inactive on a Jetpack site,
240 + * since Settings > Sharing is where our settings live. See needs_own_sharing_menu().
224 241 */
225 242 public function sharing_page() {
226 243 $this->updated_message();
227 244 ?>
@@ -232,16 +249,14 @@
232 249 /** This action is documented in modules/sharedaddy/sharing.php */
233 250 do_action( 'pre_admin_screen_sharing' );
234 251 ?>
235 252 <?php $this->sharing_block(); ?>
236 - </div>
253 + </div>
237 254 <?php
238 255 }
239 256
240 257 /**
241 258 * Returns the settings have been saved message.
242 - *
243 - * @deprecated 13.2
244 259 */
245 260 public function updated_message() {
246 261 // 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.
247 262 if ( isset( $_GET['update'] ) && 'saved' === $_GET['update'] ) {
@@ -249,15 +264,17 @@
249 264 }
250 265 }
251 266
252 267 /**
253 - * Returns just the "sharing buttons" w/ like option block, so it can be inserted into different sharing page contexts
268 + * Returns the Likes options block, so it can be inserted into different sharing page contexts.
254 269 *
255 - * @deprecated 13.2
270 + * Only rendered when the Sharing (sharedaddy) module is off, which is why the heading
271 + * does not mention sharing buttons: what lands under it is the Likes settings, the
272 + * "Show buttons on" setting that governs where Likes appear, and the Twitter Site Tag.
256 273 */
257 274 public function sharing_block() {
258 275 ?>
259 - <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2>
276 + <h2><?php esc_html_e( 'Likes and Sharing', 'jetpack' ); ?></h2>
260 277 <form method="post" action="">
261 278 <table class="form-table">
262 279 <tbody>
263 280 <?php
@@ -269,9 +286,9 @@
269 286
270 287 <p class="submit">
271 288 <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" />
272 289 <?php wp_nonce_field( 'sharing-options' ); ?>
273 - </form>
290 + </form>
274 291 <?php
275 292 }
276 293
277 294 /**
@@ -285,8 +302,12 @@
285 302 if ( ! $post || is_wp_error( $post ) ) {
286 303 return false;
287 304 }
288 305
306 + if ( ! empty( $post->post_password ) ) {
307 + return false;
308 + }
309 +
289 310 $sitewide_likes_enabled = (bool) $this->is_enabled_sitewide();
290 311 $post_likes_switched = get_post_meta( $post->ID, 'switch_like_status', true );
291 312
292 313 /*
@@ -439,9 +460,9 @@
439 460 * @return bool
440 461 */
441 462 public function is_single_post_enabled( $post_type = 'post' ) {
442 463 $options = $this->get_options();
443 - return (bool) apply_filters(
464 +
444 465 /**
445 466 * Filters whether Likes should be enabled on single posts.
446 467 *
447 468 * The dynamic part of the filter, {$post_type}, allows you to specific the post type where Likes should be enabled.
@@ -451,11 +472,14 @@
451 472 * @since 2.2.0
452 473 *
453 474 * @param bool $enabled Are Post Likes enabled on single posts?
454 475 */
476 + $post_likes_enabled = apply_filters(
455 477 "wpl_is_single_{$post_type}_disabled",
456 - (bool) in_array( $post_type, $options['show'], true )
478 + in_array( $post_type, $options['show'], true )
457 479 );
480 +
481 + return (bool) $post_likes_enabled;
458 482 }
459 483
460 484 /**
461 485 * Get the 'disabled_likes' option from the DB of the current blog.
@@ -466,12 +490,45 @@
466 490 $setting = array();
467 491 $setting['disabled'] = get_option( 'disabled_likes' );
468 492 $sharing = get_option( 'sharing-options', array() );
469 493
494 + if ( ! is_array( $sharing ) ) {
495 + $sharing = array();
496 + }
497 + if ( ! isset( $sharing['global'] ) || ! is_array( $sharing['global'] ) ) {
498 + $sharing['global'] = array();
499 + }
500 +
470 501 // Default visibility settings
471 502 if ( ! isset( $sharing['global']['show'] ) ) {
472 - $sharing['global']['show'] = array( 'post', 'page' );
503 + $public_commentable_cpts = array_filter(
504 + get_post_types(
505 + array(
506 + 'public' => true,
507 + '_builtin' => false,
508 + )
509 + ),
510 + function ( $post_type ) {
511 + return post_type_supports( $post_type, 'comments' );
512 + }
513 + );
514 + $public_commentable_cpts = array_values( $public_commentable_cpts );
473 515
516 + /**
517 + * Filters the default post types that show Likes when no sharing settings have been saved.
518 + *
519 + * Only applies when the site has never explicitly configured Likes visibility.
520 + * Once a site owner saves sharing settings, those are used instead.
521 + *
522 + * @since 16.2
523 + *
524 + * @param string[] $post_types Array of post type slugs that will show Likes by default.
525 + */
526 + $sharing['global']['show'] = apply_filters(
527 + 'jetpack_likes_default_post_types',
528 + array_merge( array( 'post', 'page' ), $public_commentable_cpts )
529 + );
530 +
474 531 // Scalar check
475 532 } elseif ( is_scalar( $sharing['global']['show'] ) ) {
476 533 switch ( $sharing['global']['show'] ) {
477 534 case 'posts':
@@ -485,10 +542,11 @@
485 542 break;
486 543 }
487 544 }
488 545
489 - // Ensure it's always an array (even if not previously empty or scalar)
490 - $setting['show'] = ! empty( $sharing['global']['show'] ) ? (array) $sharing['global']['show'] : array();
546 + // Ensure it's always an array (even if not previously empty or scalar).
547 + $show = $sharing['global']['show'] ?? array();
548 + $setting['show'] = ! empty( $show ) ? (array) $show : array();
491 549
492 550 /**
493 551 * Filters where the Likes are displayed.
494 552 *
@@ -516,9 +574,9 @@
516 574 * @since 2.2.0
517 575 *
518 576 * @param bool $enabled Are Post Likes enabled on archive/front/search pages?
519 577 */
520 - return (bool) apply_filters( 'wpl_is_index_disabled', (bool) in_array( 'index', $options['show'], true ) );
578 + return (bool) apply_filters( 'wpl_is_index_disabled', in_array( 'index', $options['show'], true ) );
521 579 }
522 580
523 581 /**
524 582 * Are Post Likes enabled on single pages?
@@ -535,9 +593,9 @@
535 593 * @since 2.2.0
536 594 *
537 595 * @param bool $enabled Are Post Likes enabled on single pages?
538 596 */
539 - return (bool) apply_filters( 'wpl_is_single_page_disabled', (bool) in_array( 'page', $options['show'], true ) );
597 + return (bool) apply_filters( 'wpl_is_single_page_disabled', in_array( 'page', $options['show'], true ) );
540 598 }
541 599
542 600 /**
543 601 * Are Media Likes enabled on single pages?
@@ -554,9 +612,9 @@
554 612 * @since 2.2.0
555 613 *
556 614 * @param bool $enabled Are Post Likes enabled on attachment pages?
557 615 */
558 - return (bool) apply_filters( 'wpl_is_attachment_disabled', (bool) in_array( 'attachment', $options['show'], true ) );
616 + return (bool) apply_filters( 'wpl_is_attachment_disabled', in_array( 'attachment', $options['show'], true ) );
559 617 }
560 618
561 619 /**
562 620 * The actual options block to be inserted into the sharing page.
@@ -732,9 +790,9 @@
732 790 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.
733 791 /** This action is documented in modules/sharedaddy/sharing.php */
734 792 do_action( 'sharing_admin_update' );
735 793 wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) );
736 - die();
794 + die( 0 );
737 795 }
738 796 }
739 797 }
740 798