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 | jetpack_vendor/automattic/jetpack-sync/src/class-settings.php +67 -35 13.6.2 → 16.3-beta View file →
@@ -61,8 +61,9 @@
61 61 'checksum_disable' => true,
62 62 'dedicated_sync_enabled' => true,
63 63 'custom_queue_table_enabled' => true,
64 64 'wpcom_rest_api_enabled' => true,
65 + 'sync_actions_blacklist' => true,
65 66 );
66 67
67 68 /**
68 69 * Whether WordPress is currently running an import.
@@ -114,9 +115,9 @@
114 115 */
115 116 public static function get_settings() {
116 117 $settings = array();
117 118 foreach ( array_keys( self::$valid_settings ) as $setting ) {
118 - $settings[ $setting ] = self::get_setting( $setting );
119 + $settings[ $setting ] = static::get_setting( $setting );
119 120 }
120 121
121 122 return $settings;
122 123 }
@@ -282,8 +283,9 @@
282 283
283 284 /**
284 285 * Regular option update and handling
285 286 */
287 + $updated = false;
286 288 if ( self::is_network_setting( $setting ) ) {
287 289 if ( is_multisite() && is_main_site() ) {
288 290 $updated = update_site_option( self::SETTINGS_OPTION_PREFIX . $setting, $value );
289 291 }
@@ -301,28 +303,23 @@
301 303 // Do not enable Dedicated Sync if we cannot spawn a Dedicated Sync request.
302 304 if ( 'dedicated_sync_enabled' === $setting && $updated && (bool) $value ) {
303 305 if ( ! Dedicated_Sender::can_spawn_dedicated_sync_request() ) {
304 306 update_option( self::SETTINGS_OPTION_PREFIX . $setting, 0, true );
305 - }
306 - }
307 + $listener = Listener::get_instance();
308 + // Remove the last two actions from the queue since we failed to enable Dedicated Sync.
309 + // Those would be `updated_option` with `jetpack_sync_settings_dedicated_sync_enabled` set to 1 and then 0 again.
310 + $queue = $listener->get_sync_queue();
311 + $items = $queue->peek_newest( 2 );
312 + $key = 'jetpack_sync_settings_dedicated_sync_enabled';
307 313
308 - // Do not enable wpcom rest api if we cannot send a test request.
309 -
310 - if ( 'wpcom_rest_api_enabled' === $setting && $updated && (bool) $value ) {
311 - $sender = Sender::get_instance();
312 - $data = array(
313 - 'timestamp' => microtime( true ),
314 - );
315 - $items = $sender->send_action( 'jetpack_sync_wpcom_rest_api_enable_test', $data );
316 - // If we can't send a test request, disable the setting and send action tolog the error.
317 - if ( is_wp_error( $items ) ) {
318 - update_option( self::SETTINGS_OPTION_PREFIX . $setting, 0, true );
319 - $data = array(
320 - 'timestamp' => microtime( true ),
321 - 'response_code' => $items->get_error_code(),
322 - 'response_body' => $items->get_error_message() ?? '',
323 - );
324 - $sender->send_action( 'jetpack_sync_wpcom_rest_api_enable_error', $data );
314 + if (
315 + isset( $items[0][1][0] )
316 + && isset( $items[1][1][0] )
317 + && $items[0][1][0] === $key
318 + && $items[1][1][0] === $key
319 + ) {
320 + $queue->pop_newest( 2 );
321 + }
325 322 }
326 323 }
327 324 }
328 325 }
@@ -349,9 +346,9 @@
349 346 *
350 347 * @return string SQL WHERE clause.
351 348 */
352 349 public static function get_blacklisted_post_types_sql() {
353 - return 'post_type NOT IN (\'' . implode( '\', \'', array_map( 'esc_sql', self::get_setting( 'post_types_blacklist' ) ) ) . '\')';
350 + return 'post_type NOT IN (\'' . implode( '\', \'', array_map( 'esc_sql', static::get_setting( 'post_types_blacklist' ) ) ) . '\')';
354 351 }
355 352
356 353 /**
357 354 * Returns escaped values for disallowed post types.
@@ -364,9 +361,9 @@
364 361 public static function get_disallowed_post_types_structured() {
365 362 return array(
366 363 'post_type' => array(
367 364 'operator' => 'NOT IN',
368 - 'values' => array_map( 'esc_sql', self::get_setting( 'post_types_blacklist' ) ),
365 + 'values' => array_map( 'esc_sql', static::get_setting( 'post_types_blacklist' ) ),
369 366 ),
370 367 );
371 368 }
372 369
@@ -379,12 +376,30 @@
379 376 *
380 377 * @return string SQL WHERE clause.
381 378 */
382 379 public static function get_blacklisted_taxonomies_sql() {
383 - return "taxonomy NOT IN ('" . implode( "', '", array_map( 'esc_sql', self::get_setting( 'taxonomies_blacklist' ) ) ) . "')";
380 + return "taxonomy NOT IN ('" . implode( "', '", array_map( 'esc_sql', static::get_setting( 'taxonomies_blacklist' ) ) ) . "')";
384 381 }
385 382
386 383 /**
384 + * Returns escaped SQL for whitelisted taxonomies.
385 + * Can be injected directly into a WHERE clause.
386 + *
387 + * @access public
388 + * @static
389 + *
390 + * @return string SQL WHERE clause.
391 + */
392 + public static function get_whitelisted_taxonomies_sql() {
393 + global $wp_taxonomies;
394 +
395 + $allowed_taxonomies = array_keys( $wp_taxonomies );
396 + $allowed_taxonomies = array_diff( $allowed_taxonomies, static::get_setting( 'taxonomies_blacklist' ) );
397 +
398 + return "taxonomy IN ('" . implode( "', '", array_map( 'esc_sql', $allowed_taxonomies ) ) . "')";
399 + }
400 +
401 + /**
387 402 * Returns escaped SQL for blacklisted post meta.
388 403 * Can be injected directly into a WHERE clause.
389 404 *
390 405 * @access public
@@ -392,9 +407,9 @@
392 407 *
393 408 * @return string SQL WHERE clause.
394 409 */
395 410 public static function get_whitelisted_post_meta_sql() {
396 - return 'meta_key IN (\'' . implode( '\', \'', array_map( 'esc_sql', self::get_setting( 'post_meta_whitelist' ) ) ) . '\')';
411 + return 'meta_key IN (\'' . implode( '\', \'', array_map( 'esc_sql', static::get_setting( 'post_meta_whitelist' ) ) ) . '\')';
397 412 }
398 413
399 414 /**
400 415 * Returns escaped SQL for allowed post meta keys.
@@ -407,9 +422,9 @@
407 422 public static function get_allowed_post_meta_structured() {
408 423 return array(
409 424 'meta_key' => array(
410 425 'operator' => 'IN',
411 - 'values' => array_map( 'esc_sql', self::get_setting( 'post_meta_whitelist' ) ),
426 + 'values' => array_map( 'esc_sql', static::get_setting( 'post_meta_whitelist' ) ),
412 427 ),
413 428 );
414 429 }
415 430
@@ -424,9 +439,9 @@
424 439 public static function get_blacklisted_taxonomies_structured() {
425 440 return array(
426 441 'taxonomy' => array(
427 442 'operator' => 'NOT IN',
428 - 'values' => array_map( 'esc_sql', self::get_setting( 'taxonomies_blacklist' ) ),
443 + 'values' => array_map( 'esc_sql', static::get_setting( 'taxonomies_blacklist' ) ),
429 444 ),
430 445 );
431 446 }
432 447
@@ -441,9 +456,9 @@
441 456 public static function get_allowed_taxonomies_structured() {
442 457 global $wp_taxonomies;
443 458
444 459 $allowed_taxonomies = array_keys( $wp_taxonomies );
445 - $allowed_taxonomies = array_diff( $allowed_taxonomies, self::get_setting( 'taxonomies_blacklist' ) );
460 + $allowed_taxonomies = array_diff( $allowed_taxonomies, static::get_setting( 'taxonomies_blacklist' ) );
446 461 return array(
447 462 'taxonomy' => array(
448 463 'operator' => 'IN',
449 464 'values' => array_map( 'esc_sql', $allowed_taxonomies ),
@@ -460,9 +475,9 @@
460 475 *
461 476 * @return string SQL WHERE clause.
462 477 */
463 478 public static function get_whitelisted_comment_meta_sql() {
464 - return 'meta_key IN (\'' . implode( '\', \'', array_map( 'esc_sql', self::get_setting( 'comment_meta_whitelist' ) ) ) . '\')';
479 + return 'meta_key IN (\'' . implode( '\', \'', array_map( 'esc_sql', static::get_setting( 'comment_meta_whitelist' ) ) ) . '\')';
465 480 }
466 481
467 482 /**
468 483 * Returns SQL-escaped values for allowed post meta keys.
@@ -475,9 +490,9 @@
475 490 public static function get_allowed_comment_meta_structured() {
476 491 return array(
477 492 'meta_key' => array(
478 493 'operator' => 'IN',
479 - 'values' => array_map( 'esc_sql', self::get_setting( 'comment_meta_whitelist' ) ),
494 + 'values' => array_map( 'esc_sql', static::get_setting( 'comment_meta_whitelist' ) ),
480 495 ),
481 496 );
482 497 }
483 498
@@ -505,8 +520,25 @@
505 520 );
506 521 }
507 522
508 523 /**
524 + * Returns structured filter values for allowed comment types.
525 + *
526 + * @access public
527 + * @static
528 + *
529 + * @return array Comment type filter values.
530 + */
531 + public static function get_allowed_comment_types_structured() {
532 + return array(
533 + 'comment_type' => array(
534 + 'operator' => 'IN',
535 + 'values' => array_map( 'esc_sql', Defaults::get_comment_types_whitelist() ),
536 + ),
537 + );
538 + }
539 +
540 + /**
509 541 * Returns escaped SQL for comments, excluding any spam comments.
510 542 * Can be injected directly into a WHERE clause.
511 543 *
512 544 * @access public
@@ -572,9 +604,9 @@
572 604 *
573 605 * @return boolean Whether sync is enabled.
574 606 */
575 607 public static function is_sync_enabled() {
576 - return ! ( self::get_setting( 'disable' ) || self::get_setting( 'network_disable' ) );
608 + return ! ( static::get_setting( 'disable' ) || static::get_setting( 'network_disable' ) );
577 609 }
578 610
579 611 /**
580 612 * Set the WP cron state.
@@ -663,9 +695,9 @@
663 695 *
664 696 * @return boolean Whether sync is enabled.
665 697 */
666 698 public static function is_sender_enabled( $queue_id ) {
667 - return (bool) self::get_setting( $queue_id . '_sender_enabled' );
699 + return (bool) static::get_setting( $queue_id . '_sender_enabled' );
668 700 }
669 701
670 702 /**
671 703 * Whether checksums are enabled.
@@ -675,9 +707,9 @@
675 707 *
676 708 * @return boolean Whether sync is enabled.
677 709 */
678 710 public static function is_checksum_enabled() {
679 - return ! (bool) self::get_setting( 'checksum_disable' );
711 + return ! (bool) static::get_setting( 'checksum_disable' );
680 712 }
681 713
682 714 /**
683 715 * Whether dedicated Sync flow is enabled.
@@ -687,9 +719,9 @@
687 719 *
688 720 * @return boolean Whether dedicated Sync flow is enabled.
689 721 */
690 722 public static function is_dedicated_sync_enabled() {
691 - return (bool) self::get_setting( 'dedicated_sync_enabled' );
723 + return (bool) static::get_setting( 'dedicated_sync_enabled' );
692 724 }
693 725
694 726 /**
695 727 * Whether custom queue table is enabled.
@@ -699,9 +731,9 @@
699 731 *
700 732 * @return boolean Whether custom queue table is enabled.
701 733 */
702 734 public static function is_custom_queue_table_enabled() {
703 - return (bool) self::get_setting( 'custom_queue_table_enabled' );
735 + return (bool) static::get_setting( 'custom_queue_table_enabled' );
704 736 }
705 737
706 738 /**
707 739 * Whether wpcom rest api is enabled.
@@ -711,7 +743,7 @@
711 743 *
712 744 * @return boolean Whether wpcom rest api is enabled.
713 745 */
714 746 public static function is_wpcom_rest_api_enabled() {
715 - return (bool) self::get_setting( 'wpcom_rest_api_enabled' );
747 + return (bool) static::get_setting( 'wpcom_rest_api_enabled' );
716 748 }
717 749 }