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 +87 -21 12.7.316.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,15 +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.
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().
211 231 */
212 232 public function sharing_menu() {
213 233 add_submenu_page( 'options-general.php', esc_html__( 'Sharing Settings', 'jetpack' ), esc_html__( 'Sharing', 'jetpack' ), 'manage_options', 'sharing', array( $this, 'sharing_page' ) );
214 234 }
@@ -215,9 +235,10 @@
215 235
216 236 /**
217 237 * Provides a sharing page with the sharing_global_options hook
218 238 * so we can display the setting.
219 - * Only ran if sharedaddy and publicize are not already active.
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().
220 241 */
221 242 public function sharing_page() {
222 243 $this->updated_message();
223 244 ?>
@@ -228,9 +249,9 @@
228 249 /** This action is documented in modules/sharedaddy/sharing.php */
229 250 do_action( 'pre_admin_screen_sharing' );
230 251 ?>
231 252 <?php $this->sharing_block(); ?>
232 - </div>
253 + </div>
233 254 <?php
234 255 }
235 256
236 257 /**
@@ -243,13 +264,17 @@
243 264 }
244 265 }
245 266
246 267 /**
247 - * 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.
269 + *
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.
248 273 */
249 274 public function sharing_block() {
250 275 ?>
251 - <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2>
276 + <h2><?php esc_html_e( 'Likes and Sharing', 'jetpack' ); ?></h2>
252 277 <form method="post" action="">
253 278 <table class="form-table">
254 279 <tbody>
255 280 <?php
@@ -261,9 +286,9 @@
261 286
262 287 <p class="submit">
263 288 <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" />
264 289 <?php wp_nonce_field( 'sharing-options' ); ?>
265 - </form>
290 + </form>
266 291 <?php
267 292 }
268 293
269 294 /**
@@ -277,8 +302,12 @@
277 302 if ( ! $post || is_wp_error( $post ) ) {
278 303 return false;
279 304 }
280 305
306 + if ( ! empty( $post->post_password ) ) {
307 + return false;
308 + }
309 +
281 310 $sitewide_likes_enabled = (bool) $this->is_enabled_sitewide();
282 311 $post_likes_switched = get_post_meta( $post->ID, 'switch_like_status', true );
283 312
284 313 /*
@@ -431,9 +460,9 @@
431 460 * @return bool
432 461 */
433 462 public function is_single_post_enabled( $post_type = 'post' ) {
434 463 $options = $this->get_options();
435 - return (bool) apply_filters(
464 +
436 465 /**
437 466 * Filters whether Likes should be enabled on single posts.
438 467 *
439 468 * The dynamic part of the filter, {$post_type}, allows you to specific the post type where Likes should be enabled.
@@ -443,11 +472,14 @@
443 472 * @since 2.2.0
444 473 *
445 474 * @param bool $enabled Are Post Likes enabled on single posts?
446 475 */
476 + $post_likes_enabled = apply_filters(
447 477 "wpl_is_single_{$post_type}_disabled",
448 - (bool) in_array( $post_type, $options['show'], true )
478 + in_array( $post_type, $options['show'], true )
449 479 );
480 +
481 + return (bool) $post_likes_enabled;
450 482 }
451 483
452 484 /**
453 485 * Get the 'disabled_likes' option from the DB of the current blog.
@@ -458,12 +490,45 @@
458 490 $setting = array();
459 491 $setting['disabled'] = get_option( 'disabled_likes' );
460 492 $sharing = get_option( 'sharing-options', array() );
461 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 +
462 501 // Default visibility settings
463 502 if ( ! isset( $sharing['global']['show'] ) ) {
464 - $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 );
465 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 +
466 531 // Scalar check
467 532 } elseif ( is_scalar( $sharing['global']['show'] ) ) {
468 533 switch ( $sharing['global']['show'] ) {
469 534 case 'posts':
@@ -477,10 +542,11 @@
477 542 break;
478 543 }
479 544 }
480 545
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();
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();
483 549
484 550 /**
485 551 * Filters where the Likes are displayed.
486 552 *
@@ -508,9 +574,9 @@
508 574 * @since 2.2.0
509 575 *
510 576 * @param bool $enabled Are Post Likes enabled on archive/front/search pages?
511 577 */
512 - 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 ) );
513 579 }
514 580
515 581 /**
516 582 * Are Post Likes enabled on single pages?
@@ -527,9 +593,9 @@
527 593 * @since 2.2.0
528 594 *
529 595 * @param bool $enabled Are Post Likes enabled on single pages?
530 596 */
531 - 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 ) );
532 598 }
533 599
534 600 /**
535 601 * Are Media Likes enabled on single pages?
@@ -546,9 +612,9 @@
546 612 * @since 2.2.0
547 613 *
548 614 * @param bool $enabled Are Post Likes enabled on attachment pages?
549 615 */
550 - 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 ) );
551 617 }
552 618
553 619 /**
554 620 * The actual options block to be inserted into the sharing page.
@@ -724,9 +790,9 @@
724 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.
725 791 /** This action is documented in modules/sharedaddy/sharing.php */
726 792 do_action( 'sharing_admin_update' );
727 793 wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) );
728 - die();
794 + die( 0 );
729 795 }
730 796 }
731 797 }
732 798