← All changes
|
jetpack_vendor/automattic/jetpack-sync/src/class-settings.php
+87
-19
12.9.5
→
16.3-beta
View file →
| @@ -60,8 +60,10 @@ | ||
| 60 | 60 | 'full_sync_limits' => true, |
| 61 | 61 | 'checksum_disable' => true, |
| 62 | 62 | 'dedicated_sync_enabled' => true, |
| 63 | 63 | 'custom_queue_table_enabled' => true, |
| 64 | + 'wpcom_rest_api_enabled' => true, | |
| 65 | + 'sync_actions_blacklist' => true, | |
| 64 | 66 | ); |
| 65 | 67 | |
| 66 | 68 | /** |
| 67 | 69 | * Whether WordPress is currently running an import. |
| @@ -113,9 +115,9 @@ | ||
| 113 | 115 | */ |
| 114 | 116 | public static function get_settings() { |
| 115 | 117 | $settings = array(); |
| 116 | 118 | foreach ( array_keys( self::$valid_settings ) as $setting ) { |
| 117 | - $settings[ $setting ] = self::get_setting( $setting ); | |
| 119 | + $settings[ $setting ] = static::get_setting( $setting ); | |
| 118 | 120 | } |
| 119 | 121 | |
| 120 | 122 | return $settings; |
| 121 | 123 | } |
| @@ -268,12 +270,15 @@ | ||
| 268 | 270 | $sender = Sender::get_instance(); |
| 269 | 271 | $sender->send_action( 'jetpack_sync_storage_error_custom_migrate', $data ); |
| 270 | 272 | } |
| 271 | 273 | } elseif ( $old_value && ! $value ) { |
| 272 | - /** | |
| 273 | - * The custom table has been disabled, migrate what we can from the custom table to the options table. | |
| 274 | - */ | |
| 275 | - 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 | + } | |
| 276 | 281 | } |
| 277 | 282 | } |
| 278 | 283 | |
| 279 | 284 | /** |
| @@ -278,8 +283,9 @@ | ||
| 278 | 283 | |
| 279 | 284 | /** |
| 280 | 285 | * Regular option update and handling |
| 281 | 286 | */ |
| 287 | + $updated = false; | |
| 282 | 288 | if ( self::is_network_setting( $setting ) ) { |
| 283 | 289 | if ( is_multisite() && is_main_site() ) { |
| 284 | 290 | $updated = update_site_option( self::SETTINGS_OPTION_PREFIX . $setting, $value ); |
| 285 | 291 | } |
| @@ -297,8 +303,23 @@ | ||
| 297 | 303 | // Do not enable Dedicated Sync if we cannot spawn a Dedicated Sync request. |
| 298 | 304 | if ( 'dedicated_sync_enabled' === $setting && $updated && (bool) $value ) { |
| 299 | 305 | if ( ! Dedicated_Sender::can_spawn_dedicated_sync_request() ) { |
| 300 | 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 | + } | |
| 301 | 322 | } |
| 302 | 323 | } |
| 303 | 324 | } |
| 304 | 325 | } |
| @@ -325,9 +346,9 @@ | ||
| 325 | 346 | * |
| 326 | 347 | * @return string SQL WHERE clause. |
| 327 | 348 | */ |
| 328 | 349 | public static function get_blacklisted_post_types_sql() { |
| 329 | - 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' ) ) ) . '\')'; | |
| 330 | 351 | } |
| 331 | 352 | |
| 332 | 353 | /** |
| 333 | 354 | * Returns escaped values for disallowed post types. |
| @@ -340,9 +361,9 @@ | ||
| 340 | 361 | public static function get_disallowed_post_types_structured() { |
| 341 | 362 | return array( |
| 342 | 363 | 'post_type' => array( |
| 343 | 364 | 'operator' => 'NOT IN', |
| 344 | - 'values' => array_map( 'esc_sql', self::get_setting( 'post_types_blacklist' ) ), | |
| 365 | + 'values' => array_map( 'esc_sql', static::get_setting( 'post_types_blacklist' ) ), | |
| 345 | 366 | ), |
| 346 | 367 | ); |
| 347 | 368 | } |
| 348 | 369 | |
| @@ -355,12 +376,30 @@ | ||
| 355 | 376 | * |
| 356 | 377 | * @return string SQL WHERE clause. |
| 357 | 378 | */ |
| 358 | 379 | public static function get_blacklisted_taxonomies_sql() { |
| 359 | - 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' ) ) ) . "')"; | |
| 360 | 381 | } |
| 361 | 382 | |
| 362 | 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 | + /** | |
| 363 | 402 | * Returns escaped SQL for blacklisted post meta. |
| 364 | 403 | * Can be injected directly into a WHERE clause. |
| 365 | 404 | * |
| 366 | 405 | * @access public |
| @@ -368,9 +407,9 @@ | ||
| 368 | 407 | * |
| 369 | 408 | * @return string SQL WHERE clause. |
| 370 | 409 | */ |
| 371 | 410 | public static function get_whitelisted_post_meta_sql() { |
| 372 | - 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' ) ) ) . '\')'; | |
| 373 | 412 | } |
| 374 | 413 | |
| 375 | 414 | /** |
| 376 | 415 | * Returns escaped SQL for allowed post meta keys. |
| @@ -383,9 +422,9 @@ | ||
| 383 | 422 | public static function get_allowed_post_meta_structured() { |
| 384 | 423 | return array( |
| 385 | 424 | 'meta_key' => array( |
| 386 | 425 | 'operator' => 'IN', |
| 387 | - 'values' => array_map( 'esc_sql', self::get_setting( 'post_meta_whitelist' ) ), | |
| 426 | + 'values' => array_map( 'esc_sql', static::get_setting( 'post_meta_whitelist' ) ), | |
| 388 | 427 | ), |
| 389 | 428 | ); |
| 390 | 429 | } |
| 391 | 430 | |
| @@ -400,9 +439,9 @@ | ||
| 400 | 439 | public static function get_blacklisted_taxonomies_structured() { |
| 401 | 440 | return array( |
| 402 | 441 | 'taxonomy' => array( |
| 403 | 442 | 'operator' => 'NOT IN', |
| 404 | - 'values' => array_map( 'esc_sql', self::get_setting( 'taxonomies_blacklist' ) ), | |
| 443 | + 'values' => array_map( 'esc_sql', static::get_setting( 'taxonomies_blacklist' ) ), | |
| 405 | 444 | ), |
| 406 | 445 | ); |
| 407 | 446 | } |
| 408 | 447 | |
| @@ -417,9 +456,9 @@ | ||
| 417 | 456 | public static function get_allowed_taxonomies_structured() { |
| 418 | 457 | global $wp_taxonomies; |
| 419 | 458 | |
| 420 | 459 | $allowed_taxonomies = array_keys( $wp_taxonomies ); |
| 421 | - $allowed_taxonomies = array_diff( $allowed_taxonomies, self::get_setting( 'taxonomies_blacklist' ) ); | |
| 460 | + $allowed_taxonomies = array_diff( $allowed_taxonomies, static::get_setting( 'taxonomies_blacklist' ) ); | |
| 422 | 461 | return array( |
| 423 | 462 | 'taxonomy' => array( |
| 424 | 463 | 'operator' => 'IN', |
| 425 | 464 | 'values' => array_map( 'esc_sql', $allowed_taxonomies ), |
| @@ -436,9 +475,9 @@ | ||
| 436 | 475 | * |
| 437 | 476 | * @return string SQL WHERE clause. |
| 438 | 477 | */ |
| 439 | 478 | public static function get_whitelisted_comment_meta_sql() { |
| 440 | - 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' ) ) ) . '\')'; | |
| 441 | 480 | } |
| 442 | 481 | |
| 443 | 482 | /** |
| 444 | 483 | * Returns SQL-escaped values for allowed post meta keys. |
| @@ -451,9 +490,9 @@ | ||
| 451 | 490 | public static function get_allowed_comment_meta_structured() { |
| 452 | 491 | return array( |
| 453 | 492 | 'meta_key' => array( |
| 454 | 493 | 'operator' => 'IN', |
| 455 | - 'values' => array_map( 'esc_sql', self::get_setting( 'comment_meta_whitelist' ) ), | |
| 494 | + 'values' => array_map( 'esc_sql', static::get_setting( 'comment_meta_whitelist' ) ), | |
| 456 | 495 | ), |
| 457 | 496 | ); |
| 458 | 497 | } |
| 459 | 498 | |
| @@ -481,8 +520,25 @@ | ||
| 481 | 520 | ); |
| 482 | 521 | } |
| 483 | 522 | |
| 484 | 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 | + /** | |
| 485 | 541 | * Returns escaped SQL for comments, excluding any spam comments. |
| 486 | 542 | * Can be injected directly into a WHERE clause. |
| 487 | 543 | * |
| 488 | 544 | * @access public |
| @@ -548,9 +604,9 @@ | ||
| 548 | 604 | * |
| 549 | 605 | * @return boolean Whether sync is enabled. |
| 550 | 606 | */ |
| 551 | 607 | public static function is_sync_enabled() { |
| 552 | - return ! ( self::get_setting( 'disable' ) || self::get_setting( 'network_disable' ) ); | |
| 608 | + return ! ( static::get_setting( 'disable' ) || static::get_setting( 'network_disable' ) ); | |
| 553 | 609 | } |
| 554 | 610 | |
| 555 | 611 | /** |
| 556 | 612 | * Set the WP cron state. |
| @@ -639,9 +695,9 @@ | ||
| 639 | 695 | * |
| 640 | 696 | * @return boolean Whether sync is enabled. |
| 641 | 697 | */ |
| 642 | 698 | public static function is_sender_enabled( $queue_id ) { |
| 643 | - return (bool) self::get_setting( $queue_id . '_sender_enabled' ); | |
| 699 | + return (bool) static::get_setting( $queue_id . '_sender_enabled' ); | |
| 644 | 700 | } |
| 645 | 701 | |
| 646 | 702 | /** |
| 647 | 703 | * Whether checksums are enabled. |
| @@ -651,9 +707,9 @@ | ||
| 651 | 707 | * |
| 652 | 708 | * @return boolean Whether sync is enabled. |
| 653 | 709 | */ |
| 654 | 710 | public static function is_checksum_enabled() { |
| 655 | - return ! (bool) self::get_setting( 'checksum_disable' ); | |
| 711 | + return ! (bool) static::get_setting( 'checksum_disable' ); | |
| 656 | 712 | } |
| 657 | 713 | |
| 658 | 714 | /** |
| 659 | 715 | * Whether dedicated Sync flow is enabled. |
| @@ -663,9 +719,9 @@ | ||
| 663 | 719 | * |
| 664 | 720 | * @return boolean Whether dedicated Sync flow is enabled. |
| 665 | 721 | */ |
| 666 | 722 | public static function is_dedicated_sync_enabled() { |
| 667 | - return (bool) self::get_setting( 'dedicated_sync_enabled' ); | |
| 723 | + return (bool) static::get_setting( 'dedicated_sync_enabled' ); | |
| 668 | 724 | } |
| 669 | 725 | |
| 670 | 726 | /** |
| 671 | 727 | * Whether custom queue table is enabled. |
| @@ -675,7 +731,19 @@ | ||
| 675 | 731 | * |
| 676 | 732 | * @return boolean Whether custom queue table is enabled. |
| 677 | 733 | */ |
| 678 | 734 | public static function is_custom_queue_table_enabled() { |
| 679 | - return (bool) self::get_setting( 'custom_queue_table_enabled' ); | |
| 735 | + return (bool) static::get_setting( 'custom_queue_table_enabled' ); | |
| 736 | + } | |
| 737 | + | |
| 738 | + /** | |
| 739 | + * Whether wpcom rest api is enabled. | |
| 740 | + * | |
| 741 | + * @access public | |
| 742 | + * @static | |
| 743 | + * | |
| 744 | + * @return boolean Whether wpcom rest api is enabled. | |
| 745 | + */ | |
| 746 | + public static function is_wpcom_rest_api_enabled() { | |
| 747 | + return (bool) static::get_setting( 'wpcom_rest_api_enabled' ); | |
| 680 | 748 | } |
| 681 | 749 | } |