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 +74 -39 13.3.3 → 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 }
@@ -269,12 +270,15 @@
269 270 $sender = Sender::get_instance();
270 271 $sender->send_action( 'jetpack_sync_storage_error_custom_migrate', $data );
271 272 }
272 273 } elseif ( $old_value && ! $value ) {
273 - /**
274 - * The custom table has been disabled, migrate what we can from the custom table to the options table.
275 - */
276 - Queue_Storage_Table::migrate_from_custom_table_to_options_table();
274 + if ( ! get_transient( Queue_Storage_Table::CUSTOM_QUEUE_TABLE_DISABLE_WPDB_ERROR_NOT_EXIST_FLAG ) ) {
275 + /**
276 + * The custom table has been disabled, migrate what we can from the custom table to the options table unless
277 + * the custom table doesn't exist in the DB.
278 + */
279 + Queue_Storage_Table::migrate_from_custom_table_to_options_table();
280 + }
277 281 }
278 282 }
279 283
280 284 /**
@@ -279,8 +283,9 @@
279 283
280 284 /**
281 285 * Regular option update and handling
282 286 */
287 + $updated = false;
283 288 if ( self::is_network_setting( $setting ) ) {
284 289 if ( is_multisite() && is_main_site() ) {
285 290 $updated = update_site_option( self::SETTINGS_OPTION_PREFIX . $setting, $value );
286 291 }
@@ -298,28 +303,23 @@
298 303 // Do not enable Dedicated Sync if we cannot spawn a Dedicated Sync request.
299 304 if ( 'dedicated_sync_enabled' === $setting && $updated && (bool) $value ) {
300 305 if ( ! Dedicated_Sender::can_spawn_dedicated_sync_request() ) {
301 306 update_option( self::SETTINGS_OPTION_PREFIX . $setting, 0, true );
302 - }
303 - }
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';
304 313
305 - // Do not enable wpcom rest api if we cannot send a test request.
306 -
307 - if ( 'wpcom_rest_api_enabled' === $setting && $updated && (bool) $value ) {
308 - $sender = Sender::get_instance();
309 - $data = array(
310 - 'timestamp' => microtime( true ),
311 - );
312 - $items = $sender->send_action( 'jetpack_sync_wpcom_rest_api_enable_test', $data );
313 - // If we can't send a test request, disable the setting and send action tolog the error.
314 - if ( is_wp_error( $items ) ) {
315 - update_option( self::SETTINGS_OPTION_PREFIX . $setting, 0, true );
316 - $data = array(
317 - 'timestamp' => microtime( true ),
318 - 'response_code' => $items->get_error_code(),
319 - 'response_body' => $items->get_error_message() ?? '',
320 - );
321 - $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 + }
322 322 }
323 323 }
324 324 }
325 325 }
@@ -346,9 +346,9 @@
346 346 *
347 347 * @return string SQL WHERE clause.
348 348 */
349 349 public static function get_blacklisted_post_types_sql() {
350 - 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' ) ) ) . '\')';
351 351 }
352 352
353 353 /**
354 354 * Returns escaped values for disallowed post types.
@@ -361,9 +361,9 @@
361 361 public static function get_disallowed_post_types_structured() {
362 362 return array(
363 363 'post_type' => array(
364 364 'operator' => 'NOT IN',
365 - 'values' => array_map( 'esc_sql', self::get_setting( 'post_types_blacklist' ) ),
365 + 'values' => array_map( 'esc_sql', static::get_setting( 'post_types_blacklist' ) ),
366 366 ),
367 367 );
368 368 }
369 369
@@ -376,12 +376,30 @@
376 376 *
377 377 * @return string SQL WHERE clause.
378 378 */
379 379 public static function get_blacklisted_taxonomies_sql() {
380 - 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' ) ) ) . "')";
381 381 }
382 382
383 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 + /**
384 402 * Returns escaped SQL for blacklisted post meta.
385 403 * Can be injected directly into a WHERE clause.
386 404 *
387 405 * @access public
@@ -389,9 +407,9 @@
389 407 *
390 408 * @return string SQL WHERE clause.
391 409 */
392 410 public static function get_whitelisted_post_meta_sql() {
393 - 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' ) ) ) . '\')';
394 412 }
395 413
396 414 /**
397 415 * Returns escaped SQL for allowed post meta keys.
@@ -404,9 +422,9 @@
404 422 public static function get_allowed_post_meta_structured() {
405 423 return array(
406 424 'meta_key' => array(
407 425 'operator' => 'IN',
408 - 'values' => array_map( 'esc_sql', self::get_setting( 'post_meta_whitelist' ) ),
426 + 'values' => array_map( 'esc_sql', static::get_setting( 'post_meta_whitelist' ) ),
409 427 ),
410 428 );
411 429 }
412 430
@@ -421,9 +439,9 @@
421 439 public static function get_blacklisted_taxonomies_structured() {
422 440 return array(
423 441 'taxonomy' => array(
424 442 'operator' => 'NOT IN',
425 - 'values' => array_map( 'esc_sql', self::get_setting( 'taxonomies_blacklist' ) ),
443 + 'values' => array_map( 'esc_sql', static::get_setting( 'taxonomies_blacklist' ) ),
426 444 ),
427 445 );
428 446 }
429 447
@@ -438,9 +456,9 @@
438 456 public static function get_allowed_taxonomies_structured() {
439 457 global $wp_taxonomies;
440 458
441 459 $allowed_taxonomies = array_keys( $wp_taxonomies );
442 - $allowed_taxonomies = array_diff( $allowed_taxonomies, self::get_setting( 'taxonomies_blacklist' ) );
460 + $allowed_taxonomies = array_diff( $allowed_taxonomies, static::get_setting( 'taxonomies_blacklist' ) );
443 461 return array(
444 462 'taxonomy' => array(
445 463 'operator' => 'IN',
446 464 'values' => array_map( 'esc_sql', $allowed_taxonomies ),
@@ -457,9 +475,9 @@
457 475 *
458 476 * @return string SQL WHERE clause.
459 477 */
460 478 public static function get_whitelisted_comment_meta_sql() {
461 - 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' ) ) ) . '\')';
462 480 }
463 481
464 482 /**
465 483 * Returns SQL-escaped values for allowed post meta keys.
@@ -472,9 +490,9 @@
472 490 public static function get_allowed_comment_meta_structured() {
473 491 return array(
474 492 'meta_key' => array(
475 493 'operator' => 'IN',
476 - 'values' => array_map( 'esc_sql', self::get_setting( 'comment_meta_whitelist' ) ),
494 + 'values' => array_map( 'esc_sql', static::get_setting( 'comment_meta_whitelist' ) ),
477 495 ),
478 496 );
479 497 }
480 498
@@ -502,8 +520,25 @@
502 520 );
503 521 }
504 522
505 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 + /**
506 541 * Returns escaped SQL for comments, excluding any spam comments.
507 542 * Can be injected directly into a WHERE clause.
508 543 *
509 544 * @access public
@@ -569,9 +604,9 @@
569 604 *
570 605 * @return boolean Whether sync is enabled.
571 606 */
572 607 public static function is_sync_enabled() {
573 - return ! ( self::get_setting( 'disable' ) || self::get_setting( 'network_disable' ) );
608 + return ! ( static::get_setting( 'disable' ) || static::get_setting( 'network_disable' ) );
574 609 }
575 610
576 611 /**
577 612 * Set the WP cron state.
@@ -660,9 +695,9 @@
660 695 *
661 696 * @return boolean Whether sync is enabled.
662 697 */
663 698 public static function is_sender_enabled( $queue_id ) {
664 - return (bool) self::get_setting( $queue_id . '_sender_enabled' );
699 + return (bool) static::get_setting( $queue_id . '_sender_enabled' );
665 700 }
666 701
667 702 /**
668 703 * Whether checksums are enabled.
@@ -672,9 +707,9 @@
672 707 *
673 708 * @return boolean Whether sync is enabled.
674 709 */
675 710 public static function is_checksum_enabled() {
676 - return ! (bool) self::get_setting( 'checksum_disable' );
711 + return ! (bool) static::get_setting( 'checksum_disable' );
677 712 }
678 713
679 714 /**
680 715 * Whether dedicated Sync flow is enabled.
@@ -684,9 +719,9 @@
684 719 *
685 720 * @return boolean Whether dedicated Sync flow is enabled.
686 721 */
687 722 public static function is_dedicated_sync_enabled() {
688 - return (bool) self::get_setting( 'dedicated_sync_enabled' );
723 + return (bool) static::get_setting( 'dedicated_sync_enabled' );
689 724 }
690 725
691 726 /**
692 727 * Whether custom queue table is enabled.
@@ -696,9 +731,9 @@
696 731 *
697 732 * @return boolean Whether custom queue table is enabled.
698 733 */
699 734 public static function is_custom_queue_table_enabled() {
700 - return (bool) self::get_setting( 'custom_queue_table_enabled' );
735 + return (bool) static::get_setting( 'custom_queue_table_enabled' );
701 736 }
702 737
703 738 /**
704 739 * Whether wpcom rest api is enabled.
@@ -708,7 +743,7 @@
708 743 *
709 744 * @return boolean Whether wpcom rest api is enabled.
710 745 */
711 746 public static function is_wpcom_rest_api_enabled() {
712 - return (bool) self::get_setting( 'wpcom_rest_api_enabled' );
747 + return (bool) static::get_setting( 'wpcom_rest_api_enabled' );
713 748 }
714 749 }