PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3 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 All 508 releases
← All changes | jetpack_vendor/automattic/jetpack-sync/src/class-settings.php +75 -20 13.2.4 → 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,8 +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 );
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';
313 +
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 + }
302 322 }
303 323 }
304 324 }
305 325 }
@@ -326,9 +346,9 @@
326 346 *
327 347 * @return string SQL WHERE clause.
328 348 */
329 349 public static function get_blacklisted_post_types_sql() {
330 - 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' ) ) ) . '\')';
331 351 }
332 352
333 353 /**
334 354 * Returns escaped values for disallowed post types.
@@ -341,9 +361,9 @@
341 361 public static function get_disallowed_post_types_structured() {
342 362 return array(
343 363 'post_type' => array(
344 364 'operator' => 'NOT IN',
345 - 'values' => array_map( 'esc_sql', self::get_setting( 'post_types_blacklist' ) ),
365 + 'values' => array_map( 'esc_sql', static::get_setting( 'post_types_blacklist' ) ),
346 366 ),
347 367 );
348 368 }
349 369
@@ -356,12 +376,30 @@
356 376 *
357 377 * @return string SQL WHERE clause.
358 378 */
359 379 public static function get_blacklisted_taxonomies_sql() {
360 - 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' ) ) ) . "')";
361 381 }
362 382
363 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 + /**
364 402 * Returns escaped SQL for blacklisted post meta.
365 403 * Can be injected directly into a WHERE clause.
366 404 *
367 405 * @access public
@@ -369,9 +407,9 @@
369 407 *
370 408 * @return string SQL WHERE clause.
371 409 */
372 410 public static function get_whitelisted_post_meta_sql() {
373 - 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' ) ) ) . '\')';
374 412 }
375 413
376 414 /**
377 415 * Returns escaped SQL for allowed post meta keys.
@@ -384,9 +422,9 @@
384 422 public static function get_allowed_post_meta_structured() {
385 423 return array(
386 424 'meta_key' => array(
387 425 'operator' => 'IN',
388 - 'values' => array_map( 'esc_sql', self::get_setting( 'post_meta_whitelist' ) ),
426 + 'values' => array_map( 'esc_sql', static::get_setting( 'post_meta_whitelist' ) ),
389 427 ),
390 428 );
391 429 }
392 430
@@ -401,9 +439,9 @@
401 439 public static function get_blacklisted_taxonomies_structured() {
402 440 return array(
403 441 'taxonomy' => array(
404 442 'operator' => 'NOT IN',
405 - 'values' => array_map( 'esc_sql', self::get_setting( 'taxonomies_blacklist' ) ),
443 + 'values' => array_map( 'esc_sql', static::get_setting( 'taxonomies_blacklist' ) ),
406 444 ),
407 445 );
408 446 }
409 447
@@ -418,9 +456,9 @@
418 456 public static function get_allowed_taxonomies_structured() {
419 457 global $wp_taxonomies;
420 458
421 459 $allowed_taxonomies = array_keys( $wp_taxonomies );
422 - $allowed_taxonomies = array_diff( $allowed_taxonomies, self::get_setting( 'taxonomies_blacklist' ) );
460 + $allowed_taxonomies = array_diff( $allowed_taxonomies, static::get_setting( 'taxonomies_blacklist' ) );
423 461 return array(
424 462 'taxonomy' => array(
425 463 'operator' => 'IN',
426 464 'values' => array_map( 'esc_sql', $allowed_taxonomies ),
@@ -437,9 +475,9 @@
437 475 *
438 476 * @return string SQL WHERE clause.
439 477 */
440 478 public static function get_whitelisted_comment_meta_sql() {
441 - 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' ) ) ) . '\')';
442 480 }
443 481
444 482 /**
445 483 * Returns SQL-escaped values for allowed post meta keys.
@@ -452,9 +490,9 @@
452 490 public static function get_allowed_comment_meta_structured() {
453 491 return array(
454 492 'meta_key' => array(
455 493 'operator' => 'IN',
456 - 'values' => array_map( 'esc_sql', self::get_setting( 'comment_meta_whitelist' ) ),
494 + 'values' => array_map( 'esc_sql', static::get_setting( 'comment_meta_whitelist' ) ),
457 495 ),
458 496 );
459 497 }
460 498
@@ -482,8 +520,25 @@
482 520 );
483 521 }
484 522
485 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 + /**
486 541 * Returns escaped SQL for comments, excluding any spam comments.
487 542 * Can be injected directly into a WHERE clause.
488 543 *
489 544 * @access public
@@ -549,9 +604,9 @@
549 604 *
550 605 * @return boolean Whether sync is enabled.
551 606 */
552 607 public static function is_sync_enabled() {
553 - return ! ( self::get_setting( 'disable' ) || self::get_setting( 'network_disable' ) );
608 + return ! ( static::get_setting( 'disable' ) || static::get_setting( 'network_disable' ) );
554 609 }
555 610
556 611 /**
557 612 * Set the WP cron state.
@@ -640,9 +695,9 @@
640 695 *
641 696 * @return boolean Whether sync is enabled.
642 697 */
643 698 public static function is_sender_enabled( $queue_id ) {
644 - return (bool) self::get_setting( $queue_id . '_sender_enabled' );
699 + return (bool) static::get_setting( $queue_id . '_sender_enabled' );
645 700 }
646 701
647 702 /**
648 703 * Whether checksums are enabled.
@@ -652,9 +707,9 @@
652 707 *
653 708 * @return boolean Whether sync is enabled.
654 709 */
655 710 public static function is_checksum_enabled() {
656 - return ! (bool) self::get_setting( 'checksum_disable' );
711 + return ! (bool) static::get_setting( 'checksum_disable' );
657 712 }
658 713
659 714 /**
660 715 * Whether dedicated Sync flow is enabled.
@@ -664,9 +719,9 @@
664 719 *
665 720 * @return boolean Whether dedicated Sync flow is enabled.
666 721 */
667 722 public static function is_dedicated_sync_enabled() {
668 - return (bool) self::get_setting( 'dedicated_sync_enabled' );
723 + return (bool) static::get_setting( 'dedicated_sync_enabled' );
669 724 }
670 725
671 726 /**
672 727 * Whether custom queue table is enabled.
@@ -676,9 +731,9 @@
676 731 *
677 732 * @return boolean Whether custom queue table is enabled.
678 733 */
679 734 public static function is_custom_queue_table_enabled() {
680 - return (bool) self::get_setting( 'custom_queue_table_enabled' );
735 + return (bool) static::get_setting( 'custom_queue_table_enabled' );
681 736 }
682 737
683 738 /**
684 739 * Whether wpcom rest api is enabled.
@@ -688,7 +743,7 @@
688 743 *
689 744 * @return boolean Whether wpcom rest api is enabled.
690 745 */
691 746 public static function is_wpcom_rest_api_enabled() {
692 - return (bool) self::get_setting( 'wpcom_rest_api_enabled' );
747 + return (bool) static::get_setting( 'wpcom_rest_api_enabled' );
693 748 }
694 749 }