summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/sync')
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-actions.php103
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-defaults.php60
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-functions.php90
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-json-deflate-array-codec.php5
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-listener.php67
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-attachments.php2
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-callables.php33
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-comments.php28
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-constants.php2
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-full-sync.php30
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-import.php1
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-menus.php10
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-meta.php22
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-network-options.php13
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-options.php16
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-plugins.php44
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-posts.php45
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-terms.php21
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-themes.php124
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-updates.php100
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-users.php110
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-woocommerce.php10
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module-wp-super-cache.php40
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-module.php25
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-modules.php2
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-queue.php79
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-sender.php40
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-server.php4
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-settings.php44
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-simple-codec.php2
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-users.php2
-rw-r--r--plugins/jetpack/sync/class.jetpack-sync-wp-replicastore.php120
-rw-r--r--plugins/jetpack/sync/interface.jetpack-sync-replicastore.php1
33 files changed, 740 insertions, 555 deletions
diff --git a/plugins/jetpack/sync/class.jetpack-sync-actions.php b/plugins/jetpack/sync/class.jetpack-sync-actions.php
index 252d37d0..b3fb39ab 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-actions.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-actions.php
@@ -9,9 +9,9 @@ require_once dirname( __FILE__ ) . '/class.jetpack-sync-modules.php';
* It also binds the action to send data to WPCOM to Jetpack's XMLRPC client object.
*/
class Jetpack_Sync_Actions {
- static $sender = null;
- static $listener = null;
- const DEFAULT_SYNC_CRON_INTERVAL_NAME = 'jetpack_sync_interval';
+ static $sender = null;
+ static $listener = null;
+ const DEFAULT_SYNC_CRON_INTERVAL_NAME = 'jetpack_sync_interval';
const DEFAULT_SYNC_CRON_INTERVAL_VALUE = 300; // 5 * MINUTE_IN_SECONDS;
static function init() {
@@ -23,7 +23,7 @@ class Jetpack_Sync_Actions {
if ( self::sync_via_cron_allowed() ) {
self::init_sync_cron_jobs();
- } else if ( wp_next_scheduled( 'jetpack_sync_cron' ) ) {
+ } elseif ( wp_next_scheduled( 'jetpack_sync_cron' ) ) {
self::clear_sync_cron_jobs();
}
// When importing via cron, do not sync
@@ -67,9 +67,10 @@ class Jetpack_Sync_Actions {
*
* @param bool should we load sync sender code for this request
*/
- if ( apply_filters( 'jetpack_sync_sender_should_load',
+ if ( apply_filters(
+ 'jetpack_sync_sender_should_load',
(
- ( isset( $_SERVER["REQUEST_METHOD"] ) && 'POST' === $_SERVER['REQUEST_METHOD'] )
+ ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] )
||
current_user_can( 'manage_options' )
||
@@ -87,9 +88,9 @@ class Jetpack_Sync_Actions {
static function sync_allowed() {
require_once dirname( __FILE__ ) . '/class.jetpack-sync-settings.php';
return ( ! Jetpack_Sync_Settings::get_setting( 'disable' )
- && ( doing_action( 'jetpack_user_authorized' ) || Jetpack::is_active() )
- && ! ( Jetpack::is_development_mode() || Jetpack::is_staging_site() ) )
- || defined( 'PHPUNIT_JETPACK_TESTSUITE' );
+ && ( doing_action( 'jetpack_user_authorized' ) || Jetpack::is_active() )
+ && ! ( Jetpack::is_development_mode() || Jetpack::is_staging_site() ) )
+ || defined( 'PHPUNIT_JETPACK_TESTSUITE' );
}
static function sync_via_cron_allowed() {
@@ -122,8 +123,8 @@ class Jetpack_Sync_Actions {
'queue' => $queue_id, // sync or full_sync
'home' => Jetpack_Sync_Functions::home_url(), // Send home url option to check for Identity Crisis server-side
'siteurl' => Jetpack_Sync_Functions::site_url(), // Send siteurl option to check for Identity Crisis server-side
- 'cd' => sprintf( '%.4f', $checkout_duration), // Time spent retrieving queue items from the DB
- 'pd' => sprintf( '%.4f', $preprocess_duration), // Time spent converting queue items into data to send
+ 'cd' => sprintf( '%.4f', $checkout_duration ), // Time spent retrieving queue items from the DB
+ 'pd' => sprintf( '%.4f', $preprocess_duration ), // Time spent converting queue items into data to send
);
// Has the site opted in to IDC mitigation?
@@ -148,11 +149,13 @@ class Jetpack_Sync_Actions {
$url = add_query_arg( $query_args, Jetpack::xmlrpc_api_url() );
- $rpc = new Jetpack_IXR_Client( array(
- 'url' => $url,
- 'user_id' => JETPACK_MASTER_USER,
- 'timeout' => $query_args['timeout'],
- ) );
+ $rpc = new Jetpack_IXR_Client(
+ array(
+ 'url' => $url,
+ 'user_id' => JETPACK_MASTER_USER,
+ 'timeout' => $query_args['timeout'],
+ )
+ );
$result = $rpc->query( 'jetpack.syncActions', $data );
@@ -164,11 +167,11 @@ class Jetpack_Sync_Actions {
// Check if WordPress.com IDC mitigation blocked the sync request
if ( is_array( $response ) && isset( $response['error_code'] ) ) {
- $error_code = $response['error_code'];
+ $error_code = $response['error_code'];
$allowed_idc_error_codes = array(
'jetpack_url_mismatch',
'jetpack_home_url_mismatch',
- 'jetpack_site_url_mismatch'
+ 'jetpack_site_url_mismatch',
);
if ( in_array( $error_code, $allowed_idc_error_codes ) ) {
@@ -194,10 +197,10 @@ class Jetpack_Sync_Actions {
}
$initial_sync_config = array(
- 'options' => true,
- 'functions' => true,
- 'constants' => true,
- 'users' => array( get_current_user_id() ),
+ 'options' => true,
+ 'functions' => true,
+ 'constants' => true,
+ 'users' => array( get_current_user_id() ),
);
if ( is_multisite() ) {
@@ -229,10 +232,10 @@ class Jetpack_Sync_Actions {
if ( ! isset( $schedules[ self::DEFAULT_SYNC_CRON_INTERVAL_NAME ] ) ) {
$schedules[ self::DEFAULT_SYNC_CRON_INTERVAL_NAME ] = array(
'interval' => self::DEFAULT_SYNC_CRON_INTERVAL_VALUE,
- 'display' => sprintf(
+ 'display' => sprintf(
esc_html( _n( 'Every minute', 'Every %d minutes', intval( self::DEFAULT_SYNC_CRON_INTERVAL_VALUE / 60 ), 'jetpack' ) ),
intval( self::DEFAULT_SYNC_CRON_INTERVAL_VALUE / 60 )
- )
+ ),
);
}
return $schedules;
@@ -319,7 +322,7 @@ class Jetpack_Sync_Actions {
}
static function sanitize_filtered_sync_cron_schedule( $schedule ) {
- $schedule = sanitize_key( $schedule );
+ $schedule = sanitize_key( $schedule );
$schedules = wp_get_schedules();
// Make sure that the schedule has actually been registered using the `cron_intervals` filter.
@@ -331,7 +334,7 @@ class Jetpack_Sync_Actions {
}
static function get_start_time_offset( $schedule = '', $hook = '' ) {
- $start_time_offset = is_multisite()
+ $start_time_offset = is_multisite()
? mt_rand( 0, ( 2 * self::DEFAULT_SYNC_CRON_INTERVAL_VALUE ) )
: 0;
@@ -345,12 +348,14 @@ class Jetpack_Sync_Actions {
* @param string $hook
* @param string $schedule
*/
- return intval( apply_filters(
- 'jetpack_sync_cron_start_time_offset',
- $start_time_offset,
- $hook,
- $schedule
- ) );
+ return intval(
+ apply_filters(
+ 'jetpack_sync_cron_start_time_offset',
+ $start_time_offset,
+ $hook,
+ $schedule
+ )
+ );
}
static function maybe_schedule_sync_cron( $schedule, $hook ) {
@@ -363,7 +368,7 @@ class Jetpack_Sync_Actions {
if ( ! wp_next_scheduled( $hook ) ) {
// Schedule a job to send pending queue items once a minute
wp_schedule_event( $start_time, $schedule, $hook );
- } else if ( $schedule != wp_get_schedule( $hook ) ) {
+ } elseif ( $schedule != wp_get_schedule( $hook ) ) {
// If the schedule has changed, update the schedule
wp_clear_scheduled_hook( $hook );
wp_schedule_event( $start_time, $schedule, $hook );
@@ -411,33 +416,35 @@ class Jetpack_Sync_Actions {
if ( ! empty( $old_version ) && $is_new_sync_upgrade && version_compare( $old_version, '4.5', '<' ) ) {
require_once dirname( __FILE__ ) . '/class.jetpack-sync-settings.php';
self::clear_sync_cron_jobs();
- Jetpack_Sync_Settings::update_settings( array(
- 'render_filtered_content' => Jetpack_Sync_Defaults::$default_render_filtered_content
- ) );
+ Jetpack_Sync_Settings::update_settings(
+ array(
+ 'render_filtered_content' => Jetpack_Sync_Defaults::$default_render_filtered_content,
+ )
+ );
}
}
static function get_sync_status() {
self::initialize_sender();
- $sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' );
- $queue = self::$sender->get_sync_queue();
- $full_queue = self::$sender->get_full_sync_queue();
+ $sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' );
+ $queue = self::$sender->get_sync_queue();
+ $full_queue = self::$sender->get_full_sync_queue();
$cron_timestamps = array_keys( _get_cron_array() );
- $next_cron = $cron_timestamps[0] - time();
+ $next_cron = $cron_timestamps[0] - time();
$full_sync_status = ( $sync_module ) ? $sync_module->get_status() : array();
return array_merge(
$full_sync_status,
array(
- 'cron_size' => count( $cron_timestamps ),
- 'next_cron' => $next_cron,
- 'queue_size' => $queue->size(),
- 'queue_lag' => $queue->lag(),
- 'queue_next_sync' => ( self::$sender->get_next_sync_time( 'sync' ) - microtime( true ) ),
- 'full_queue_size' => $full_queue->size(),
- 'full_queue_lag' => $full_queue->lag(),
- 'full_queue_next_sync' => ( self::$sender->get_next_sync_time( 'full_sync' ) - microtime( true ) ),
+ 'cron_size' => count( $cron_timestamps ),
+ 'next_cron' => $next_cron,
+ 'queue_size' => $queue->size(),
+ 'queue_lag' => $queue->lag(),
+ 'queue_next_sync' => ( self::$sender->get_next_sync_time( 'sync' ) - microtime( true ) ),
+ 'full_queue_size' => $full_queue->size(),
+ 'full_queue_lag' => $full_queue->lag(),
+ 'full_queue_next_sync' => ( self::$sender->get_next_sync_time( 'full_sync' ) - microtime( true ) ),
)
);
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-defaults.php b/plugins/jetpack/sync/class.jetpack-sync-defaults.php
index 6727e18b..1452bd7e 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-defaults.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-defaults.php
@@ -1,5 +1,5 @@
<?php
-require_once( JETPACK__PLUGIN_DIR . 'modules/sso/class.jetpack-sso-helpers.php' );
+require_once JETPACK__PLUGIN_DIR . 'modules/sso/class.jetpack-sso-helpers.php';
/**
* Just some defaults that we share with the server
@@ -100,6 +100,7 @@ class Jetpack_Sync_Defaults {
'wp_mobile_app_promos',
'monitor_receive_notifications',
'post_by_email_address',
+ 'jetpack_mailchimp',
'jetpack_protect_key',
'jetpack_protect_global_whitelist',
'jetpack_sso_require_two_step',
@@ -138,6 +139,9 @@ class Jetpack_Sync_Defaults {
'wordads_display_page',
'wordads_display_archive',
'wordads_custom_adstxt',
+ 'site_segment',
+ 'site_user_type',
+ 'site_vertical',
);
public static function get_options_whitelist() {
@@ -193,7 +197,7 @@ class Jetpack_Sync_Defaults {
'WP_CRON_LOCK_TIMEOUT',
'PHP_VERSION',
'WP_MEMORY_LIMIT',
- 'WP_MAX_MEMORY_LIMIT'
+ 'WP_MAX_MEMORY_LIMIT',
);
public static function get_constants_whitelist() {
@@ -240,7 +244,9 @@ class Jetpack_Sync_Defaults {
'site_icon_url' => array( 'Jetpack_Sync_Functions', 'site_icon_url' ),
'roles' => array( 'Jetpack_Sync_Functions', 'roles' ),
'timezone' => array( 'Jetpack_Sync_Functions', 'get_timezone' ),
- 'available_jetpack_blocks' => array( 'Jetpack_Gutenberg', 'get_block_availability' ),
+ 'available_jetpack_blocks' => array( 'Jetpack_Gutenberg', 'get_availability' ), // Includes both Gutenberg blocks *and* plugins
+ 'paused_themes' => array( 'Jetpack_Sync_Functions', 'get_paused_themes' ),
+ 'paused_plugins' => array( 'Jetpack_Sync_Functions', 'get_paused_plugins' ),
);
@@ -314,6 +320,7 @@ class Jetpack_Sync_Defaults {
'jp_img_sitemap_index',
'jp_vid_sitemap',
'jp_vid_sitemap_index',
+ 'vip-legacy-redirect',
);
static $default_post_checksum_columns = array(
@@ -323,7 +330,7 @@ class Jetpack_Sync_Defaults {
static $default_post_meta_checksum_columns = array(
'meta_id',
- 'meta_value'
+ 'meta_value',
);
static $default_comment_checksum_columns = array(
@@ -333,7 +340,7 @@ class Jetpack_Sync_Defaults {
static $default_comment_meta_checksum_columns = array(
'meta_id',
- 'meta_value'
+ 'meta_value',
);
static $default_option_checksum_columns = array(
@@ -420,7 +427,7 @@ class Jetpack_Sync_Defaults {
'hc_avatar',
'hc_post_as',
'hc_wpcom_id_sig',
- 'hc_foreign_user_id'
+ 'hc_foreign_user_id',
);
public static function get_comment_meta_whitelist() {
@@ -457,7 +464,8 @@ class Jetpack_Sync_Defaults {
);
static function is_whitelisted_option( $option ) {
- foreach ( self::$default_options_whitelist as $whitelisted_option ) {
+ $whitelisted_options = self::get_options_whitelist();
+ foreach ( $whitelisted_options as $whitelisted_option ) {
if ( $whitelisted_option[0] === '/' && preg_match( $whitelisted_option, $option ) ) {
return true;
} elseif ( $whitelisted_option === $option ) {
@@ -556,26 +564,26 @@ class Jetpack_Sync_Defaults {
'active_sitewide_plugins',
);
- static $default_taxonomy_whitelist = array();
- static $default_dequeue_max_bytes = 500000; // very conservative value, 1/2 MB
- static $default_upload_max_bytes = 600000; // a little bigger than the upload limit to account for serialization
- static $default_upload_max_rows = 500;
- static $default_sync_wait_time = 10; // seconds, between syncs
- static $default_sync_wait_threshold = 5; // only wait before next send if the current send took more than X seconds
- static $default_enqueue_wait_time = 10; // wait between attempting to continue a full sync, via requests
- static $default_max_queue_size = 1000;
- static $default_max_queue_lag = 900; // 15 minutes
- static $default_queue_max_writes_sec = 100; // 100 rows a second
- static $default_post_types_blacklist = array();
- static $default_post_meta_whitelist = array();
- static $default_comment_meta_whitelist = array();
- static $default_disable = 0; // completely disable sending data to wpcom
- static $default_sync_via_cron = 1; // use cron to sync
- static $default_render_filtered_content = 0; // render post_filtered_content
- static $default_max_enqueue_full_sync = 100; // max number of items to enqueue at a time when running full sync
+ static $default_taxonomy_whitelist = array();
+ static $default_dequeue_max_bytes = 500000; // very conservative value, 1/2 MB
+ static $default_upload_max_bytes = 600000; // a little bigger than the upload limit to account for serialization
+ static $default_upload_max_rows = 500;
+ static $default_sync_wait_time = 10; // seconds, between syncs
+ static $default_sync_wait_threshold = 5; // only wait before next send if the current send took more than X seconds
+ static $default_enqueue_wait_time = 10; // wait between attempting to continue a full sync, via requests
+ static $default_max_queue_size = 1000;
+ static $default_max_queue_lag = 900; // 15 minutes
+ static $default_queue_max_writes_sec = 100; // 100 rows a second
+ static $default_post_types_blacklist = array();
+ static $default_post_meta_whitelist = array();
+ static $default_comment_meta_whitelist = array();
+ static $default_disable = 0; // completely disable sending data to wpcom
+ static $default_sync_via_cron = 1; // use cron to sync
+ static $default_render_filtered_content = 0; // render post_filtered_content
+ static $default_max_enqueue_full_sync = 100; // max number of items to enqueue at a time when running full sync
static $default_max_queue_size_full_sync = 1000; // max number of total items in the full sync queue
static $default_sync_callables_wait_time = MINUTE_IN_SECONDS; // seconds before sending callables again
static $default_sync_constants_wait_time = HOUR_IN_SECONDS; // seconds before sending constants again
- static $default_sync_queue_lock_timeout = 120; // 2 minutes
- static $default_cron_sync_time_limit = 30; // 30 seconds
+ static $default_sync_queue_lock_timeout = 120; // 2 minutes
+ static $default_cron_sync_time_limit = 30; // 30 seconds
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-functions.php b/plugins/jetpack/sync/class.jetpack-sync-functions.php
index 0036aa1c..609797bb 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-functions.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-functions.php
@@ -6,10 +6,10 @@
class Jetpack_Sync_Functions {
const HTTPS_CHECK_OPTION_PREFIX = 'jetpack_sync_https_history_';
- const HTTPS_CHECK_HISTORY = 5;
+ const HTTPS_CHECK_HISTORY = 5;
public static function get_modules() {
- require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-admin.php' );
+ require_once JETPACK__PLUGIN_DIR . 'class.jetpack-admin.php';
return Jetpack_Admin::init()->get_modules();
}
@@ -21,7 +21,7 @@ class Jetpack_Sync_Functions {
$sanitized_taxonomy = self::sanitize_taxonomy( $taxonomy );
if ( ! empty( $sanitized_taxonomy ) ) {
$wp_taxonomies_without_callbacks[ $taxonomy_name ] = $sanitized_taxonomy;
- } else {
+ } else {
error_log( 'Jetpack: Encountered a recusive taxonomy:' . $taxonomy_name );
}
}
@@ -47,17 +47,17 @@ class Jetpack_Sync_Functions {
}
// Remove any meta_box_cb if they are not the default wp ones.
if ( isset( $cloned_taxonomy->meta_box_cb ) &&
- ! in_array( $cloned_taxonomy->meta_box_cb, array( 'post_tags_meta_box', 'post_categories_meta_box' ) ) ) {
+ ! in_array( $cloned_taxonomy->meta_box_cb, array( 'post_tags_meta_box', 'post_categories_meta_box' ) ) ) {
$cloned_taxonomy->meta_box_cb = null;
}
// Remove update call back
if ( isset( $cloned_taxonomy->update_count_callback ) &&
- ! is_null( $cloned_taxonomy->update_count_callback ) ) {
+ ! is_null( $cloned_taxonomy->update_count_callback ) ) {
$cloned_taxonomy->update_count_callback = null;
}
// Remove rest_controller_class if it something other then the default.
- if ( isset( $cloned_taxonomy->rest_controller_class ) &&
- 'WP_REST_Terms_Controller' !== $cloned_taxonomy->rest_controller_class ) {
+ if ( isset( $cloned_taxonomy->rest_controller_class ) &&
+ 'WP_REST_Terms_Controller' !== $cloned_taxonomy->rest_controller_class ) {
$cloned_taxonomy->rest_controller_class = null;
}
return $cloned_taxonomy;
@@ -90,7 +90,7 @@ class Jetpack_Sync_Functions {
}
public static function expand_synced_post_type( $sanitized_post_type, $post_type ) {
- $post_type = sanitize_key( $post_type );
+ $post_type = sanitize_key( $post_type );
$post_type_object = new WP_Post_Type( $post_type, $sanitized_post_type );
$post_type_object->add_supports();
$post_type_object->add_rewrite_rules();
@@ -136,12 +136,13 @@ class Jetpack_Sync_Functions {
/**
* Finds out if a site is using a version control system.
+ *
* @return bool
**/
public static function is_version_controlled() {
if ( ! class_exists( 'WP_Automatic_Updater' ) ) {
- require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
+ require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
$updater = new WP_Automatic_Updater();
@@ -150,24 +151,25 @@ class Jetpack_Sync_Functions {
/**
* Returns true if the site has file write access false otherwise.
+ *
* @return bool
**/
public static function file_system_write_access() {
if ( ! function_exists( 'get_filesystem_method' ) ) {
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
+ require_once ABSPATH . 'wp-admin/includes/file.php';
}
- require_once( ABSPATH . 'wp-admin/includes/template.php' );
+ require_once ABSPATH . 'wp-admin/includes/template.php';
$filesystem_method = get_filesystem_method();
- if ( 'direct' === $filesystem_method ) {
+ if ( 'direct' === $filesystem_method ) {
return true;
}
ob_start();
if ( ! function_exists( 'request_filesystem_credentials' ) ) {
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
+ require_once ABSPATH . 'wp-admin/includes/file.php';
}
$filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
@@ -195,8 +197,8 @@ class Jetpack_Sync_Functions {
Jetpack_Constants::get_constant( 'JETPACK_SYNC_USE_RAW_URL' )
) {
$scheme = is_ssl() ? 'https' : 'http';
- $url = self::get_raw_url( $url_type );
- $url = set_url_scheme( $url, $scheme );
+ $url = self::get_raw_url( $url_type );
+ $url = set_url_scheme( $url, $scheme );
} else {
$url = self::normalize_www_in_url( $url_type, $url_function );
}
@@ -241,12 +243,12 @@ class Jetpack_Sync_Functions {
if ( ! $parsed_url ) {
return $new_value;
}
- if ( array_key_exists ( 'scheme' , $parsed_url ) ) {
+ if ( array_key_exists( 'scheme', $parsed_url ) ) {
$scheme = $parsed_url['scheme'];
} else {
$scheme = '';
}
- $scheme_history = get_option( $option_key, array() );
+ $scheme_history = get_option( $option_key, array() );
$scheme_history[] = $scheme;
// Limit length to self::HTTPS_CHECK_HISTORY
@@ -254,13 +256,13 @@ class Jetpack_Sync_Functions {
update_option( $option_key, $scheme_history );
- $forced_scheme = in_array( 'https', $scheme_history ) ? 'https' : 'http';
+ $forced_scheme = in_array( 'https', $scheme_history ) ? 'https' : 'http';
return set_url_scheme( $new_value, $forced_scheme );
}
public static function get_raw_url( $option_name ) {
- $value = null;
+ $value = null;
$constant = ( 'home' == $option_name )
? 'WP_HOME'
: 'WP_SITEURL';
@@ -286,13 +288,13 @@ class Jetpack_Sync_Functions {
return $url;
}
- if ( $url[ 'host' ] === "www.{$option_url[ 'host' ]}" ) {
+ if ( $url['host'] === "www.{$option_url[ 'host' ]}" ) {
// remove www if not present in option URL
- $url[ 'host' ] = $option_url[ 'host' ];
+ $url['host'] = $option_url['host'];
}
- if ( $option_url[ 'host' ] === "www.{$url[ 'host' ]}" ) {
+ if ( $option_url['host'] === "www.{$url[ 'host' ]}" ) {
// add www if present in option URL
- $url[ 'host' ] = $option_url[ 'host' ];
+ $url['host'] = $option_url['host'];
}
$normalized_url = "{$url['scheme']}://{$url['host']}";
@@ -319,6 +321,7 @@ class Jetpack_Sync_Functions {
/**
* Get custom action link tags that the plugin is using
* Ref: https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)
+ *
* @return array of plugin action links (key: link name value: url)
*/
public static function get_plugins_action_links( $plugin_file_singular = null ) {
@@ -342,11 +345,8 @@ class Jetpack_Sync_Functions {
}
public static function site_icon_url( $size = 512 ) {
- if ( ! function_exists( 'get_site_icon_url' ) || ! has_site_icon() ) {
- return get_option( 'jetpack_site_icon_url' );
- }
-
- return get_site_icon_url( $size );
+ $site_icon = get_site_icon_url( $size );
+ return $site_icon ? $site_icon : get_option( 'jetpack_site_icon_url' );
}
public static function roles() {
@@ -355,15 +355,15 @@ class Jetpack_Sync_Functions {
}
/**
- * Determine time zone from WordPress' options "timezone_string"
- * and "gmt_offset".
- *
- * 1. Check if `timezone_string` is set and return it.
- * 2. Check if `gmt_offset` is set, formats UTC-offset from it and return it.
- * 3. Default to "UTC+0" if nothing is set.
- *
- * @return string
- */
+ * Determine time zone from WordPress' options "timezone_string"
+ * and "gmt_offset".
+ *
+ * 1. Check if `timezone_string` is set and return it.
+ * 2. Check if `gmt_offset` is set, formats UTC-offset from it and return it.
+ * 3. Default to "UTC+0" if nothing is set.
+ *
+ * @return string
+ */
public static function get_timezone() {
$timezone_string = get_option( 'timezone_string' );
@@ -384,4 +384,20 @@ class Jetpack_Sync_Functions {
/* translators: %s is UTC offset, e.g. "+1" */
return sprintf( __( 'UTC%s', 'jetpack' ), $formatted_gmt_offset );
}
+ // New in WP 5.1
+ public static function get_paused_themes() {
+ if ( function_exists( 'wp_paused_themes' ) ) {
+ $paused_themes = wp_paused_themes();
+ return $paused_themes->get_all();
+ }
+ return false;
+ }
+ // New in WP 5.1
+ public static function get_paused_plugins() {
+ if ( function_exists( 'wp_paused_plugins' ) ) {
+ $paused_plugins = wp_paused_plugins();
+ return $paused_plugins->get_all();
+ }
+ return false;
+ }
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-json-deflate-array-codec.php b/plugins/jetpack/sync/class.jetpack-sync-json-deflate-array-codec.php
index 8d8e6173..04d3dd7d 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-json-deflate-array-codec.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-json-deflate-array-codec.php
@@ -7,7 +7,7 @@ require_once dirname( __FILE__ ) . '/interface.jetpack-sync-codec.php';
* algorithm to compress objects serialized using json_encode
*/
class Jetpack_Sync_JSON_Deflate_Array_Codec implements iJetpack_Sync_Codec {
- const CODEC_NAME = "deflate-json-array";
+ const CODEC_NAME = 'deflate-json-array';
public function name() {
return self::CODEC_NAME;
@@ -22,7 +22,6 @@ class Jetpack_Sync_JSON_Deflate_Array_Codec implements iJetpack_Sync_Codec {
}
// @see https://gist.github.com/muhqu/820694
-
protected function json_serialize( $any ) {
if ( function_exists( 'jetpack_json_wrap' ) ) {
return wp_json_encode( jetpack_json_wrap( $any ) );
@@ -37,7 +36,7 @@ class Jetpack_Sync_JSON_Deflate_Array_Codec implements iJetpack_Sync_Codec {
private function json_wrap( &$any, $seen_nodes = array() ) {
if ( is_object( $any ) ) {
- $input = get_object_vars( $any );
+ $input = get_object_vars( $any );
$input['__o'] = 1;
} else {
$input = &$any;
diff --git a/plugins/jetpack/sync/class.jetpack-sync-listener.php b/plugins/jetpack/sync/class.jetpack-sync-listener.php
index c38e4cf7..e0a60617 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-listener.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-listener.php
@@ -10,7 +10,7 @@ require_once dirname( __FILE__ ) . '/class.jetpack-sync-actions.php';
*/
class Jetpack_Sync_Listener {
const QUEUE_STATE_CHECK_TRANSIENT = 'jetpack_sync_last_checked_queue_state';
- const QUEUE_STATE_CHECK_TIMEOUT = 300; // 5 minutes
+ const QUEUE_STATE_CHECK_TIMEOUT = 300; // 5 minutes
private $sync_queue;
private $full_sync_queue;
@@ -35,7 +35,7 @@ class Jetpack_Sync_Listener {
}
private function init() {
- $handler = array( $this, 'action_handler' );
+ $handler = array( $this, 'action_handler' );
$full_sync_handler = array( $this, 'full_sync_action_handler' );
foreach ( Jetpack_Sync_Modules::get_modules() as $module ) {
@@ -102,8 +102,8 @@ class Jetpack_Sync_Listener {
list( $queue_size, $queue_age ) = $queue_state;
return ( $queue_age < $this->sync_queue_lag_limit )
- ||
- ( ( $queue_size + 1 ) < $this->sync_queue_size_limit );
+ ||
+ ( ( $queue_size + 1 ) < $this->sync_queue_size_limit );
}
function full_sync_action_handler() {
@@ -126,7 +126,7 @@ class Jetpack_Sync_Listener {
return;
}
- // if we add any items to the queue, we should try to ensure that our script
+ // if we add any items to the queue, we should try to ensure that our script
// can't be killed before they are sent
if ( function_exists( 'ignore_user_abort' ) ) {
ignore_user_abort( true );
@@ -137,14 +137,14 @@ class Jetpack_Sync_Listener {
$currtime = microtime( true );
$is_importing = Jetpack_Sync_Settings::is_importing();
- foreach( $args_array as $args ) {
+ foreach ( $args_array as $args ) {
/**
* Modify or reject the data within an action before it is enqueued locally.
*
* @since 4.2.0
*
- * @module sync
+ * @module sync
*
* @param array The action parameters
*/
@@ -202,7 +202,7 @@ class Jetpack_Sync_Listener {
return;
}
- // if we add any items to the queue, we should try to ensure that our script
+ // if we add any items to the queue, we should try to ensure that our script
// can't be killed before they are sent
if ( function_exists( 'ignore_user_abort' ) ) {
ignore_user_abort( true );
@@ -215,26 +215,30 @@ class Jetpack_Sync_Listener {
array(
'jetpack_full_sync_start',
'jetpack_full_sync_end',
- 'jetpack_full_sync_cancel'
+ 'jetpack_full_sync_cancel',
)
)
) {
- $queue->add( array(
- $current_filter,
- $args,
- get_current_user_id(),
- microtime( true ),
- Jetpack_Sync_Settings::is_importing(),
- $this->get_actor( $current_filter, $args ),
- ) );
+ $queue->add(
+ array(
+ $current_filter,
+ $args,
+ get_current_user_id(),
+ microtime( true ),
+ Jetpack_Sync_Settings::is_importing(),
+ $this->get_actor( $current_filter, $args ),
+ )
+ );
} else {
- $queue->add( array(
- $current_filter,
- $args,
- get_current_user_id(),
- microtime( true ),
- Jetpack_Sync_Settings::is_importing()
- ) );
+ $queue->add(
+ array(
+ $current_filter,
+ $args,
+ get_current_user_id(),
+ microtime( true ),
+ Jetpack_Sync_Settings::is_importing(),
+ )
+ );
}
// since we've added some items, let's try to load the sender so we can send them as quickly as possible
@@ -247,7 +251,7 @@ class Jetpack_Sync_Listener {
}
function get_actor( $current_filter, $args ) {
- if ( 'wp_login' === $current_filter ) {
+ if ( 'wp_login' === $current_filter ) {
$user = get_user_by( 'ID', $args[1]->data->ID );
} else {
$user = wp_get_current_user();
@@ -273,8 +277,8 @@ class Jetpack_Sync_Listener {
);
if ( $this->should_send_user_data_with_actor( $current_filter ) ) {
- require_once( JETPACK__PLUGIN_DIR . 'modules/protect/shared-functions.php' );
- $actor['ip'] = jetpack_protect_get_ip();
+ require_once JETPACK__PLUGIN_DIR . 'modules/protect/shared-functions.php';
+ $actor['ip'] = jetpack_protect_get_ip();
$actor['user_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : 'unknown';
}
@@ -282,7 +286,7 @@ class Jetpack_Sync_Listener {
}
function should_send_user_data_with_actor( $current_filter ) {
- $should_send = in_array( $current_filter, array( 'wp_login', 'wp_logout', 'jetpack_valid_failed_login_attempt' ) );
+ $should_send = in_array( $current_filter, array( 'jetpack_wp_login', 'wp_logout', 'jetpack_valid_failed_login_attempt' ) );
/**
* Allow or deny sending actor's user data ( IP and UA ) during a sync event
*
@@ -297,13 +301,16 @@ class Jetpack_Sync_Listener {
}
function set_defaults() {
- $this->sync_queue = new Jetpack_Sync_Queue( 'sync' );
+ $this->sync_queue = new Jetpack_Sync_Queue( 'sync' );
$this->full_sync_queue = new Jetpack_Sync_Queue( 'full_sync' );
$this->set_queue_size_limit( Jetpack_Sync_Settings::get_setting( 'max_queue_size' ) );
$this->set_queue_lag_limit( Jetpack_Sync_Settings::get_setting( 'max_queue_lag' ) );
}
function get_request_url() {
- return 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
+ if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) {
+ return 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
+ }
+ return is_admin() ? get_admin_url( get_current_blog_id() ) : home_url();
}
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-attachments.php b/plugins/jetpack/sync/class.jetpack-sync-module-attachments.php
index b020efb7..f68ba832 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-attachments.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-attachments.php
@@ -7,7 +7,7 @@ class Jetpack_Sync_Module_Attachments extends Jetpack_Sync_Module {
public function init_listeners( $callable ) {
add_action( 'add_attachment', array( $this, 'process_add' ) );
- add_action( 'attachment_updated', array( $this, 'process_update'), 10, 3 );
+ add_action( 'attachment_updated', array( $this, 'process_update' ), 10, 3 );
add_action( 'jetpack_sync_save_update_attachment', $callable, 10, 2 );
add_action( 'jetpack_sync_save_add_attachment', $callable, 10, 2 );
add_action( 'jetpack_sync_save_attach_attachment', $callable, 10, 2 );
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-callables.php b/plugins/jetpack/sync/class.jetpack-sync-module-callables.php
index 7aa1c4d2..2db509ed 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-callables.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-callables.php
@@ -22,7 +22,7 @@ class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module {
public function init_listeners( $callable ) {
add_action( 'jetpack_sync_callable', $callable, 10, 2 );
- add_action( 'admin_init', array( $this, 'set_plugin_action_links' ), 9999 ); // Should happen very late
+ add_action( 'current_screen', array( $this, 'set_plugin_action_links' ), 9999 ); // Should happen very late
// For some options, we should always send the change right away!
$always_send_updates_to_these_options = array(
@@ -30,9 +30,12 @@ class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module {
'home',
'siteurl',
'jetpack_sync_error_idc',
+ 'paused_plugins',
+ 'paused_themes',
);
- foreach( $always_send_updates_to_these_options as $option ) {
+ foreach ( $always_send_updates_to_these_options as $option ) {
add_action( "update_option_{$option}", array( $this, 'unlock_sync_callable' ) );
+ add_action( "delete_option_{$option}", array( $this, 'unlock_sync_callable' ) );
}
// Provide a hook so that hosts can send changes to certain callables right away.
@@ -61,7 +64,7 @@ class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module {
delete_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME );
$url_callables = array( 'home_url', 'site_url', 'main_network_site_url' );
- foreach( $url_callables as $callable ) {
+ foreach ( $url_callables as $callable ) {
delete_option( Jetpack_Sync_Functions::HTTPS_CHECK_OPTION_PREFIX . $callable );
}
}
@@ -125,16 +128,18 @@ class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module {
public function set_plugin_action_links() {
if (
! class_exists( 'DOMDocument' ) ||
- ! function_exists ( 'libxml_use_internal_errors' ) ||
- ! function_exists ( 'mb_convert_encoding' )
+ ! function_exists( 'libxml_use_internal_errors' ) ||
+ ! function_exists( 'mb_convert_encoding' )
) {
return;
}
+ $current_screeen = get_current_screen();
+
$plugins_action_links = array();
// Is the transient lock in place?
$plugins_lock = get_transient( 'jetpack_plugin_api_action_links_refresh', false );
- if ( ! empty( $plugins_lock ) ) {
+ if ( ! empty( $plugins_lock ) && ( isset( $current_screeen->id ) && $current_screeen->id !== 'plugins' ) ) {
return;
}
$plugins = array_keys( Jetpack_Sync_Functions::get_plugins() );
@@ -144,19 +149,19 @@ class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module {
*/
$action_links = array(
'deactivate' => '',
- 'activate' => '',
- 'details' => '',
- 'delete' => '',
- 'edit' => ''
+ 'activate' => '',
+ 'details' => '',
+ 'delete' => '',
+ 'edit' => '',
);
/** This filter is documented in src/wp-admin/includes/class-wp-plugins-list-table.php */
$action_links = apply_filters( 'plugin_action_links', $action_links, $plugin_file, null, 'all' );
/** This filter is documented in src/wp-admin/includes/class-wp-plugins-list-table.php */
- $action_links = apply_filters( "plugin_action_links_{$plugin_file}", $action_links, $plugin_file, null, 'all' );
- $action_links = array_filter( $action_links );
+ $action_links = apply_filters( "plugin_action_links_{$plugin_file}", $action_links, $plugin_file, null, 'all' );
+ $action_links = array_filter( $action_links );
$formatted_action_links = null;
if ( ! empty( $action_links ) && count( $action_links ) > 0 ) {
- $dom_doc = new DOMDocument;
+ $dom_doc = new DOMDocument();
foreach ( $action_links as $action_link ) {
// The @ is not enough to suppress errors when dealing with libxml,
// we have to tell it directly how we want to handle errors.
@@ -250,7 +255,7 @@ class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module {
public function expand_callables( $args ) {
if ( $args[0] ) {
- $callables = $this->get_all_callables();
+ $callables = $this->get_all_callables();
$callables_checksums = array();
foreach ( $callables as $name => $value ) {
$callables_checksums[ $name ] = $this->get_check_sum( $value );
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-comments.php b/plugins/jetpack/sync/class.jetpack-sync-module-comments.php
index 2b378cf3..e6c49171 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-comments.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-comments.php
@@ -51,10 +51,10 @@ class Jetpack_Sync_Module_Comments extends Jetpack_Sync_Module {
'comment_author_url',
'comment_content',
);
- $changes = array();
+ $changes = array();
foreach ( $content_fields as $field ) {
- if ( $new_comment_with_slashes[$field] != $old_comment[$field] ) {
- $changes[$field] = array( $new_comment[$field], $old_comment[$field] );
+ if ( $new_comment_with_slashes[ $field ] != $old_comment[ $field ] ) {
+ $changes[ $field ] = array( $new_comment[ $field ], $old_comment[ $field ] );
}
}
@@ -83,10 +83,13 @@ class Jetpack_Sync_Module_Comments extends Jetpack_Sync_Module {
foreach ( array( '', 'trackback', 'pingback' ) as $comment_type ) {
foreach ( array( 'unapproved', 'approved' ) as $comment_status ) {
$comment_action_name = "comment_{$comment_status}_{$comment_type}";
- add_filter( 'jetpack_sync_before_send_' . $comment_action_name, array(
- $this,
- 'expand_wp_insert_comment',
- ) );
+ add_filter(
+ 'jetpack_sync_before_send_' . $comment_action_name,
+ array(
+ $this,
+ 'expand_wp_insert_comment',
+ )
+ );
}
}
@@ -146,6 +149,7 @@ class Jetpack_Sync_Module_Comments extends Jetpack_Sync_Module {
* Instead we pass data that will still enable us to do a checksum against the
* Jetpacks data but will prevent us from displaying the data on in the API as well as
* other services.
+ *
* @since 4.2.0
*
* @param boolean false prevent post data from bing synced to WordPress.com
@@ -175,10 +179,12 @@ class Jetpack_Sync_Module_Comments extends Jetpack_Sync_Module {
public function expand_comment_ids( $args ) {
$comment_ids = $args[0];
- $comments = get_comments( array(
- 'include_unapproved' => true,
- 'comment__in' => $comment_ids,
- ) );
+ $comments = get_comments(
+ array(
+ 'include_unapproved' => true,
+ 'comment__in' => $comment_ids,
+ )
+ );
return array(
$comments,
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-constants.php b/plugins/jetpack/sync/class.jetpack-sync-module-constants.php
index 0d08bf33..f3af3195 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-constants.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-constants.php
@@ -112,7 +112,7 @@ class Jetpack_Sync_Module_Constants extends Jetpack_Sync_Module {
public function expand_constants( $args ) {
if ( $args[0] ) {
- $constants = $this->get_all_constants();
+ $constants = $this->get_all_constants();
$constants_checksums = array();
foreach ( $constants as $name => $value ) {
$constants_checksums[ $name ] = $this->get_check_sum( $value );
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-full-sync.php b/plugins/jetpack/sync/class.jetpack-sync-module-full-sync.php
index d397fbc6..bb936482 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-full-sync.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-full-sync.php
@@ -14,7 +14,7 @@
class Jetpack_Sync_Module_Full_Sync extends Jetpack_Sync_Module {
const STATUS_OPTION_PREFIX = 'jetpack_sync_full_';
- const FULL_SYNC_TIMEOUT = 3600;
+ const FULL_SYNC_TIMEOUT = 3600;
public function name() {
return 'full-sync';
@@ -50,7 +50,7 @@ class Jetpack_Sync_Module_Full_Sync extends Jetpack_Sync_Module {
$this->update_status_option( 'started', time() );
$this->update_status_option( 'params', $module_configs );
- $enqueue_status = array();
+ $enqueue_status = array();
$full_sync_config = array();
// default value is full sync
@@ -63,7 +63,7 @@ class Jetpack_Sync_Module_Full_Sync extends Jetpack_Sync_Module {
// set default configuration, calculate totals, and save configuration if totals > 0
foreach ( Jetpack_Sync_Modules::get_modules() as $module ) {
- $module_name = $module->name();
+ $module_name = $module->name();
$module_config = isset( $module_configs[ $module_name ] ) ? $module_configs[ $module_name ] : false;
if ( ! $module_config ) {
@@ -81,7 +81,7 @@ class Jetpack_Sync_Module_Full_Sync extends Jetpack_Sync_Module {
// if there's information to process, configure this module
if ( ! is_null( $total_items ) && $total_items > 0 ) {
$full_sync_config[ $module_name ] = $module_config;
- $enqueue_status[ $module_name ] = array(
+ $enqueue_status[ $module_name ] = array(
$total_items, // total
0, // queued
false, // current state
@@ -112,7 +112,7 @@ class Jetpack_Sync_Module_Full_Sync extends Jetpack_Sync_Module {
// if full sync queue is full, don't enqueue more items
$max_queue_size_full_sync = Jetpack_Sync_Settings::get_setting( 'max_queue_size_full_sync' );
- $full_sync_queue = new Jetpack_Sync_Queue( 'full_sync' );
+ $full_sync_queue = new Jetpack_Sync_Queue( 'full_sync' );
$available_queue_slots = $max_queue_size_full_sync - $full_sync_queue->size();
@@ -140,18 +140,18 @@ class Jetpack_Sync_Module_Full_Sync extends Jetpack_Sync_Module {
|| // no enqueue status
! $enqueue_status[ $module_name ]
|| // finished enqueuing this module
- true === $enqueue_status[ $module_name ][ 2 ] ) {
+ true === $enqueue_status[ $module_name ][2] ) {
continue;
}
- list( $items_enqueued, $next_enqueue_state ) = $module->enqueue_full_sync_actions( $configs[ $module_name ], $remaining_items_to_enqueue, $enqueue_status[ $module_name ][ 2 ] );
+ list( $items_enqueued, $next_enqueue_state ) = $module->enqueue_full_sync_actions( $configs[ $module_name ], $remaining_items_to_enqueue, $enqueue_status[ $module_name ][2] );
- $enqueue_status[ $module_name ][ 2 ] = $next_enqueue_state;
+ $enqueue_status[ $module_name ][2] = $next_enqueue_state;
// if items were processed, subtract them from the limit
if ( ! is_null( $items_enqueued ) && $items_enqueued > 0 ) {
- $enqueue_status[ $module_name ][ 1 ] += $items_enqueued;
- $remaining_items_to_enqueue -= $items_enqueued;
+ $enqueue_status[ $module_name ][1] += $items_enqueued;
+ $remaining_items_to_enqueue -= $items_enqueued;
}
// stop processing if we've reached our limit of items to enqueue
@@ -217,11 +217,11 @@ class Jetpack_Sync_Module_Full_Sync extends Jetpack_Sync_Module {
}
public function is_started() {
- return !! $this->get_status_option( 'started' );
+ return ! ! $this->get_status_option( 'started' );
}
public function is_finished() {
- return !! $this->get_status_option( 'finished' );
+ return ! ! $this->get_status_option( 'finished' );
}
public function get_status() {
@@ -248,15 +248,15 @@ class Jetpack_Sync_Module_Full_Sync extends Jetpack_Sync_Module {
list( $total, $queued, $state ) = $enqueue_status[ $name ];
if ( $total ) {
- $status[ 'total' ][ $name ] = $total;
+ $status['total'][ $name ] = $total;
}
if ( $queued ) {
- $status[ 'queue' ][ $name ] = $queued;
+ $status['queue'][ $name ] = $queued;
}
if ( $sent = $this->get_status_option( "{$name}_sent" ) ) {
- $status[ 'sent' ][ $name ] = $sent;
+ $status['sent'][ $name ] = $sent;
}
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-import.php b/plugins/jetpack/sync/class.jetpack-sync-module-import.php
index bf4e274c..bc30b283 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-import.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-import.php
@@ -60,6 +60,7 @@ class Jetpack_Sync_Module_Import extends Jetpack_Sync_Module {
}
if ( 'unknown' === $importer && $this->is_importer( $backtrace, 'WP_Import' ) ) {
+ // phpcs:ignore WordPress.WP.CapitalPDangit
$importer = 'wordpress';
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-menus.php b/plugins/jetpack/sync/class.jetpack-sync-module-menus.php
index 34ce2b3f..86e2279c 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-menus.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-menus.php
@@ -19,16 +19,16 @@ class Jetpack_Sync_Module_Menus extends Jetpack_Sync_Module {
add_action( 'jetpack_sync_updated_nav_menu_update_item', $callable, 10, 4 );
add_action( 'delete_nav_menu', $callable, 10, 3 );
}
-
+
public function update_nav_menu( $menu_id, $menu_data = array() ) {
if ( empty( $menu_data ) ) {
return;
}
/**
* Helps sync log that a nav menu was updated.
- *
+ *
* @since 5.0.0
- *
+ *
* @param int $menu_id, the id of the menu
* @param object $menu_data
*/
@@ -36,7 +36,7 @@ class Jetpack_Sync_Module_Menus extends Jetpack_Sync_Module {
}
public function update_nav_menu_add_item( $menu_id, $nav_item_id, $nav_item_args ) {
- $menu_data = wp_get_nav_menu_object( $menu_id );
+ $menu_data = wp_get_nav_menu_object( $menu_id );
$this->nav_items_just_added[] = $nav_item_id;
/**
* Helps sync log that a new menu item was added.
@@ -69,7 +69,7 @@ class Jetpack_Sync_Module_Menus extends Jetpack_Sync_Module {
do_action( 'jetpack_sync_updated_nav_menu_update_item', $menu_id, $menu_data, $nav_item_id, $nav_item_args );
}
- public function remove_just_added_menu_item( $nav_item_id, $post_after ) {
+ public function remove_just_added_menu_item( $nav_item_id, $post_after ) {
if ( 'nav_menu_item' !== $post_after->post_type ) {
return;
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-meta.php b/plugins/jetpack/sync/class.jetpack-sync-module-meta.php
index 917bcefa..e3d43544 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-meta.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-meta.php
@@ -15,7 +15,7 @@ class Jetpack_Sync_Module_Meta extends Jetpack_Sync_Module {
* the meta key is, but we do know that we have missing meta for a given post or comment.
*
* @param string $object_type The type of object for which we retrieve meta. Either 'post' or 'comment'
- * @param array $config Must include 'meta_key' and 'ids' keys
+ * @param array $config Must include 'meta_key' and 'ids' keys
*
* @return array
*/
@@ -32,13 +32,13 @@ class Jetpack_Sync_Module_Meta extends Jetpack_Sync_Module {
return array();
}
- $meta_key = $config['meta_key'];
- $ids = $config['ids'];
- $object_id_column = $object_type.'_id';
+ $meta_key = $config['meta_key'];
+ $ids = $config['ids'];
+ $object_id_column = $object_type . '_id';
// Sanitize so that the array only has integer values
$ids_string = implode( ', ', array_map( 'intval', $ids ) );
- $metas = $wpdb->get_results(
+ $metas = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM {$table} WHERE {$object_id_column} IN ( {$ids_string} ) AND meta_key = %s",
$meta_key
@@ -46,14 +46,14 @@ class Jetpack_Sync_Module_Meta extends Jetpack_Sync_Module {
);
$meta_objects = array();
- foreach( (array) $metas as $meta_object ) {
- $meta_object = (array) $meta_object;
+ foreach ( (array) $metas as $meta_object ) {
+ $meta_object = (array) $meta_object;
$meta_objects[ $meta_object[ $object_id_column ] ] = array(
- 'meta_type' => $object_type,
- 'meta_id' => $meta_object['meta_id'],
- 'meta_key' => $meta_key,
+ 'meta_type' => $object_type,
+ 'meta_id' => $meta_object['meta_id'],
+ 'meta_key' => $meta_key,
'meta_value' => $meta_object['meta_value'],
- 'object_id' => $meta_object[ $object_id_column ],
+ 'object_id' => $meta_object[ $object_id_column ],
);
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-network-options.php b/plugins/jetpack/sync/class.jetpack-sync-module-network-options.php
index 458d86da..011e9bba 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-network-options.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-network-options.php
@@ -33,10 +33,13 @@ class Jetpack_Sync_Module_Network_Options extends Jetpack_Sync_Module {
}
// full sync
- add_filter( 'jetpack_sync_before_send_jetpack_full_sync_network_options', array(
- $this,
- 'expand_network_options',
- ) );
+ add_filter(
+ 'jetpack_sync_before_send_jetpack_full_sync_network_options',
+ array(
+ $this,
+ 'expand_network_options',
+ )
+ );
}
public function set_defaults() {
@@ -65,7 +68,7 @@ class Jetpack_Sync_Module_Network_Options extends Jetpack_Sync_Module {
if ( ! is_multisite() ) {
return 0;
}
-
+
return 1;
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-options.php b/plugins/jetpack/sync/class.jetpack-sync-module-options.php
index 37cb4579..287e73b9 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-options.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-options.php
@@ -71,7 +71,7 @@ class Jetpack_Sync_Module_Options extends Jetpack_Sync_Module {
// Is public so that we don't have to store so much data all the options twice.
function get_all_options() {
- $options = array();
+ $options = array();
$random_string = wp_generate_password();
foreach ( $this->options_whitelist as $option ) {
$option_value = get_option( $option, $random_string );
@@ -81,7 +81,7 @@ class Jetpack_Sync_Module_Options extends Jetpack_Sync_Module {
}
// add theme mods
- $theme_mods_option = 'theme_mods_'.get_option( 'stylesheet' );
+ $theme_mods_option = 'theme_mods_' . get_option( 'stylesheet' );
$theme_mods_value = get_option( $theme_mods_option, $random_string );
if ( $theme_mods_value === $random_string ) {
return $options;
@@ -128,7 +128,7 @@ class Jetpack_Sync_Module_Options extends Jetpack_Sync_Module {
// Set value(s) of contentless option to empty string(s)
if ( $this->is_contentless_option( $args[0] ) ) {
// Create a new array matching length of $args, containing empty strings
- $empty = array_fill( 0, count( $args ), '' );
+ $empty = array_fill( 0, count( $args ), '' );
$empty[0] = $args[0];
return $empty;
}
@@ -151,18 +151,14 @@ class Jetpack_Sync_Module_Options extends Jetpack_Sync_Module {
}
function jetpack_sync_core_icon() {
- if ( function_exists( 'get_site_icon_url' ) ) {
- $url = get_site_icon_url();
- } else {
- return;
- }
+ $url = get_site_icon_url();
- require_once( JETPACK__PLUGIN_DIR . 'modules/site-icon/site-icon-functions.php' );
+ require_once JETPACK__PLUGIN_DIR . 'modules/site-icon/site-icon-functions.php';
// If there's a core icon, maybe update the option. If not, fall back to Jetpack's.
if ( ! empty( $url ) && $url !== jetpack_site_icon_url() ) {
// This is the option that is synced with dotcom
Jetpack_Options::update_option( 'site_icon_url', $url );
- } else if ( empty( $url ) ) {
+ } elseif ( empty( $url ) ) {
Jetpack_Options::delete_option( 'site_icon_url' );
}
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-plugins.php b/plugins/jetpack/sync/class.jetpack-sync-module-plugins.php
index 8efbf35e..876526ab 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-plugins.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-plugins.php
@@ -4,7 +4,7 @@ class Jetpack_Sync_Module_Plugins extends Jetpack_Sync_Module {
private $action_handler;
private $plugin_info = array();
- private $plugins = array();
+ private $plugins = array();
public function name() {
return 'plugins';
@@ -13,16 +13,16 @@ class Jetpack_Sync_Module_Plugins extends Jetpack_Sync_Module {
public function init_listeners( $callable ) {
$this->action_handler = $callable;
- add_action( 'deleted_plugin', array( $this, 'deleted_plugin' ), 10, 2 );
+ add_action( 'deleted_plugin', array( $this, 'deleted_plugin' ), 10, 2 );
add_action( 'activated_plugin', $callable, 10, 2 );
add_action( 'deactivated_plugin', $callable, 10, 2 );
- add_action( 'delete_plugin', array( $this, 'delete_plugin') );
+ add_action( 'delete_plugin', array( $this, 'delete_plugin' ) );
add_filter( 'upgrader_pre_install', array( $this, 'populate_plugins' ), 10, 1 );
add_action( 'upgrader_process_complete', array( $this, 'on_upgrader_completion' ), 10, 2 );
add_action( 'jetpack_plugin_installed', $callable, 10, 1 );
add_action( 'jetpack_plugin_update_failed', $callable, 10, 4 );
add_action( 'jetpack_plugins_updated', $callable, 10, 2 );
- add_action( 'admin_action_update', array( $this, 'check_plugin_edit') );
+ add_action( 'admin_action_update', array( $this, 'check_plugin_edit' ) );
add_action( 'jetpack_edited_plugin', $callable, 10, 2 );
add_action( 'wp_ajax_edit-theme-plugin-file', array( $this, 'plugin_edit_ajax' ), 0 );
}
@@ -30,7 +30,7 @@ class Jetpack_Sync_Module_Plugins extends Jetpack_Sync_Module {
public function init_before_send() {
add_filter( 'jetpack_sync_before_send_activated_plugin', array( $this, 'expand_plugin_data' ) );
add_filter( 'jetpack_sync_before_send_deactivated_plugin', array( $this, 'expand_plugin_data' ) );
- //Note that we don't simply 'expand_plugin_data' on the 'delete_plugin' action here because the plugin file is deleted when that action finishes
+ // Note that we don't simply 'expand_plugin_data' on the 'delete_plugin' action here because the plugin file is deleted when that action finishes
}
public function populate_plugins( $response ) {
$this->plugins = get_plugins();
@@ -98,7 +98,6 @@ class Jetpack_Sync_Module_Plugins extends Jetpack_Sync_Module {
do_action( 'jetpack_plugins_updated', array_map( array( $this, 'get_plugin_info' ), $plugins ), $state );
break;
case 'install':
-
}
if ( 'install' === $details['action'] ) {
@@ -123,8 +122,8 @@ class Jetpack_Sync_Module_Plugins extends Jetpack_Sync_Module {
if ( isset( $plugins[ $slug ] ) ) {
return array_merge( array( 'slug' => $slug ), $plugins[ $slug ] );
};
- // Try grabbing the info from before the update
- return isset( $this->plugins[ $slug ] ) ? array_merge( array( 'slug' => $slug ), $this->plugins[ $slug ] ): array( 'slug' => $slug );
+ // Try grabbing the info from before the update
+ return isset( $this->plugins[ $slug ] ) ? array_merge( array( 'slug' => $slug ), $this->plugins[ $slug ] ) : array( 'slug' => $slug );
}
private function get_errors( $skin ) {
@@ -132,18 +131,27 @@ class Jetpack_Sync_Module_Plugins extends Jetpack_Sync_Module {
if ( is_wp_error( $errors ) ) {
$error_code = $errors->get_error_code();
if ( ! empty( $error_code ) ) {
- return array( 'code' => $error_code, 'message' => $errors->get_error_message() );
+ return array(
+ 'code' => $error_code,
+ 'message' => $errors->get_error_message(),
+ );
}
}
if ( isset( $skin->result ) ) {
$errors = $skin->result;
if ( is_wp_error( $errors ) ) {
- return array( 'code' => $errors->get_error_code(), 'message' => $errors->get_error_message() );
+ return array(
+ 'code' => $errors->get_error_code(),
+ 'message' => $errors->get_error_message(),
+ );
}
if ( false == $skin->result ) {
- return array( 'code' => 'unknown', 'message' => __( 'Unknown Plugin Update Failure', 'jetpack' ) );
+ return array(
+ 'code' => 'unknown',
+ 'message' => __( 'Unknown Plugin Update Failure', 'jetpack' ),
+ );
}
}
return false;
@@ -158,7 +166,7 @@ class Jetpack_Sync_Module_Plugins extends Jetpack_Sync_Module {
return;
}
- $plugin = $_POST['plugin'];
+ $plugin = $_POST['plugin'];
$plugins = get_plugins();
if ( ! isset( $plugins[ $plugin ] ) ) {
return;
@@ -236,16 +244,16 @@ class Jetpack_Sync_Module_Plugins extends Jetpack_Sync_Module {
public function delete_plugin( $plugin_path ) {
$full_plugin_path = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $plugin_path;
- //Checking for file existence because some sync plugin module tests simulate plugin installation and deletion without putting file on disk
+ // Checking for file existence because some sync plugin module tests simulate plugin installation and deletion without putting file on disk
if ( file_exists( $full_plugin_path ) ) {
$all_plugin_data = get_plugin_data( $full_plugin_path );
- $data = array(
- 'name' => $all_plugin_data['Name'],
+ $data = array(
+ 'name' => $all_plugin_data['Name'],
'version' => $all_plugin_data['Version'],
);
} else {
$data = array(
- 'name' => $plugin_path,
+ 'name' => $plugin_path,
'version' => 'unknown',
);
}
@@ -267,8 +275,8 @@ class Jetpack_Sync_Module_Plugins extends Jetpack_Sync_Module {
}
$all_plugins = get_plugins();
if ( isset( $all_plugins[ $plugin_path ] ) ) {
- $all_plugin_data = $all_plugins[ $plugin_path ];
- $plugin_data['name'] = $all_plugin_data['Name'];
+ $all_plugin_data = $all_plugins[ $plugin_path ];
+ $plugin_data['name'] = $all_plugin_data['Name'];
$plugin_data['version'] = $all_plugin_data['Version'];
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-posts.php b/plugins/jetpack/sync/class.jetpack-sync-module-posts.php
index 13210ac6..0c4655ff 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-posts.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-posts.php
@@ -4,7 +4,7 @@ require_once dirname( __FILE__ ) . '/class.jetpack-sync-settings.php';
class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
- private $just_published = array();
+ private $just_published = array();
private $previous_status = array();
private $action_handler;
private $import_end = false;
@@ -26,11 +26,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
public function init_listeners( $callable ) {
$this->action_handler = $callable;
- // Core < 4.7 doesn't deal with nested wp_insert_post calls very well
- global $wp_version;
- $priority = version_compare( $wp_version, '4.7-alpha', '<' ) ? 0 : 11;
-
- add_action( 'wp_insert_post', array( $this, 'wp_insert_post' ), $priority, 3 );
+ add_action( 'wp_insert_post', array( $this, 'wp_insert_post' ), 11, 3 );
add_action( 'jetpack_sync_save_post', $callable, 10, 4 );
add_action( 'deleted_post', $callable, 10 );
@@ -62,7 +58,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
* @param array $feedback_ids feedback post IDs
* @param string $meta_key to be deleted
*/
- do_action( 'jetpack_post_meta_batch_delete', $feedback_ids, '_feedback_akismet_values');
+ do_action( 'jetpack_post_meta_batch_delete', $feedback_ids, '_feedback_akismet_values' );
}
public function daily_akismet_meta_cleanup_after( $feedback_ids ) {
@@ -148,7 +144,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
function is_post_type_allowed( $post_id ) {
$post = get_post( intval( $post_id ) );
- if( $post->post_type ) {
+ if ( $post->post_type ) {
return ! in_array( $post->post_type, Jetpack_Sync_Settings::get_setting( 'post_types_blacklist' ) );
}
return false;
@@ -196,6 +192,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
* Instead we pass data that will still enable us to do a checksum against the
* Jetpacks data but will prevent us from displaying the data on in the API as well as
* other services.
+ *
* @since 4.2.0
*
* @param boolean false prevent post data from being synced to WordPress.com
@@ -232,13 +229,16 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
*
* @param array of shortcode tags to remove.
*/
- $shortcodes_to_remove = apply_filters( 'jetpack_sync_do_not_expand_shortcodes', array(
- 'gallery',
- 'slideshow'
- ) );
+ $shortcodes_to_remove = apply_filters(
+ 'jetpack_sync_do_not_expand_shortcodes',
+ array(
+ 'gallery',
+ 'slideshow',
+ )
+ );
$removed_shortcode_callbacks = array();
foreach ( $shortcodes_to_remove as $shortcode ) {
- if ( isset ( $shortcode_tags[ $shortcode ] ) ) {
+ if ( isset( $shortcode_tags[ $shortcode ] ) ) {
$removed_shortcode_callbacks[ $shortcode ] = $shortcode_tags[ $shortcode ];
}
}
@@ -293,8 +293,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
isset( $_POST['action'], $_GET['classic-editor'], $_GET['meta_box'] ) &&
'editpost' === $_POST['action'] &&
'1' === $_GET['classic-editor'] &&
- '1' === $_GET['meta_box'] &&
- Jetpack_Gutenberg::is_gutenberg_available()
+ '1' === $_GET['meta_box']
);
}
@@ -317,9 +316,9 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
false;
$state = array(
- 'is_auto_save' => (bool) Jetpack_Constants::get_constant( 'DOING_AUTOSAVE' ),
- 'previous_status' => $previous_status,
- 'just_published' => $just_published,
+ 'is_auto_save' => (bool) Jetpack_Constants::get_constant( 'DOING_AUTOSAVE' ),
+ 'previous_status' => $previous_status,
+ 'just_published' => $just_published,
'is_gutenberg_meta_box_update' => $this->is_gutenberg_meta_box_update(),
);
/**
@@ -350,7 +349,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
}
$post_flags = array(
- 'post_type' => $post->post_type
+ 'post_type' => $post->post_type,
);
$author_user_object = get_user_by( 'id', $post->post_author );
@@ -391,7 +390,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
if ( 'customize_changeset' == $post->post_type ) {
$post_content = json_decode( $post->post_content, true );
foreach ( $post_content as $key => $value ) {
- //Skip if it isn't a widget
+ // Skip if it isn't a widget
if ( 'widget_' != substr( $key, 0, strlen( 'widget_' ) ) ) {
continue;
}
@@ -403,9 +402,9 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module {
global $wp_registered_widgets;
if ( isset( $wp_registered_widgets[ $key ] ) ) {
$widget_data = array(
- 'name' => $wp_registered_widgets[ $key ]['name'],
- 'id' => $key,
- 'title' => $value['value']['title'],
+ 'name' => $wp_registered_widgets[ $key ]['name'],
+ 'id' => $key,
+ 'title' => $value['value']['title'],
);
do_action( 'jetpack_widget_edited', $widget_data );
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-terms.php b/plugins/jetpack/sync/class.jetpack-sync-module-terms.php
index 7f47ebab..59f3da09 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-terms.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-terms.php
@@ -30,7 +30,6 @@ class Jetpack_Sync_Module_Terms extends Jetpack_Sync_Module {
global $wpdb;
// TODO: process state
-
$taxonomies = get_taxonomies();
$total_chunks_counter = 0;
foreach ( $taxonomies as $taxonomy ) {
@@ -56,7 +55,7 @@ class Jetpack_Sync_Module_Terms extends Jetpack_Sync_Module {
$taxonomies = get_taxonomies();
$total_chunks_counter = 0;
foreach ( $taxonomies as $taxonomy ) {
- $total_ids = $wpdb->get_var( $wpdb->prepare( "SELECT count(term_id) FROM $wpdb->term_taxonomy WHERE taxonomy = %s", $taxonomy ) );
+ $total_ids = $wpdb->get_var( $wpdb->prepare( "SELECT count(term_id) FROM $wpdb->term_taxonomy WHERE taxonomy = %s", $taxonomy ) );
$total_chunks_counter += (int) ceil( $total_ids / self::ARRAY_CHUNK_SIZE );
}
@@ -107,23 +106,15 @@ class Jetpack_Sync_Module_Terms extends Jetpack_Sync_Module {
}
public function expand_term_ids( $args ) {
- global $wp_version;
$term_ids = $args[0];
$taxonomy = $args[1];
- // version 4.5 or higher
- if ( version_compare( $wp_version, 4.5, '>=' ) ) {
- $terms = get_terms( array(
+
+ return get_terms(
+ array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
'include' => $term_ids,
- ) );
- } else {
- $terms = get_terms( $taxonomy, array(
- 'hide_empty' => false,
- 'include' => $term_ids,
- ) );
- }
-
- return $terms;
+ )
+ );
}
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-themes.php b/plugins/jetpack/sync/class.jetpack-sync-module-themes.php
index f2a87162..e8b4185d 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-themes.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-themes.php
@@ -8,10 +8,10 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
public function init_listeners( $callable ) {
add_action( 'switch_theme', array( $this, 'sync_theme_support' ), 10, 3 );
add_action( 'jetpack_sync_current_theme_support', $callable, 10, 2 );
- add_action( 'upgrader_process_complete', array( $this, 'check_upgrader'), 10, 2 );
+ add_action( 'upgrader_process_complete', array( $this, 'check_upgrader' ), 10, 2 );
add_action( 'jetpack_installed_theme', $callable, 10, 2 );
add_action( 'jetpack_updated_themes', $callable, 10, 2 );
- add_action( 'delete_site_transient_update_themes', array( $this, 'detect_theme_deletion') );
+ add_action( 'delete_site_transient_update_themes', array( $this, 'detect_theme_deletion' ) );
add_action( 'jetpack_deleted_theme', $callable, 10, 2 );
add_filter( 'wp_redirect', array( $this, 'detect_theme_edit' ) );
add_action( 'jetpack_edited_theme', $callable, 10, 2 );
@@ -43,8 +43,8 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
}
$widget = array(
- 'name' => $widget_object->name,
- 'id' => $widget_object->id,
+ 'name' => $widget_object->name,
+ 'id' => $widget_object->id,
'title' => isset( $new_instance['title'] ) ? $new_instance['title'] : '',
);
/**
@@ -62,16 +62,16 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
public function sync_network_allowed_themes_change( $option, $value, $old_value, $network_id ) {
$all_enabled_theme_slugs = array_keys( $value );
- if ( count( $old_value ) > count( $value ) ) {
+ if ( count( $old_value ) > count( $value ) ) {
- //Suppress jetpack_network_disabled_themes sync action when theme is deleted
+ // Suppress jetpack_network_disabled_themes sync action when theme is deleted
$delete_theme_call = $this->get_delete_theme_call();
if ( ! empty( $delete_theme_call ) ) {
return;
}
$newly_disabled_theme_names = array_keys( array_diff_key( $old_value, $value ) );
- $newly_disabled_themes = $this->get_theme_details_for_slugs( $newly_disabled_theme_names );
+ $newly_disabled_themes = $this->get_theme_details_for_slugs( $newly_disabled_theme_names );
/**
* Trigger action to alert $callable sync listener that network themes were disabled
*
@@ -85,7 +85,7 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
}
$newly_enabled_theme_names = array_keys( array_diff_key( $value, $old_value ) );
- $newly_enabled_themes = $this->get_theme_details_for_slugs( $newly_enabled_theme_names );
+ $newly_enabled_themes = $this->get_theme_details_for_slugs( $newly_enabled_theme_names );
/**
* Trigger action to alert $callable sync listener that network themes were enabled
*
@@ -100,19 +100,19 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
private function get_theme_details_for_slugs( $theme_slugs ) {
$theme_data = array();
foreach ( $theme_slugs as $slug ) {
- $theme = wp_get_theme( $slug );
+ $theme = wp_get_theme( $slug );
$theme_data[ $slug ] = array(
- 'name' => $theme->get( 'Name' ),
+ 'name' => $theme->get( 'Name' ),
'version' => $theme->get( 'Version' ),
- 'uri' => $theme->get( 'ThemeURI' ),
- 'slug' => $slug,
+ 'uri' => $theme->get( 'ThemeURI' ),
+ 'slug' => $slug,
);
}
return $theme_data;
}
public function detect_theme_edit( $redirect_url ) {
- $url = wp_parse_url( admin_url( $redirect_url ) );
+ $url = wp_parse_url( admin_url( $redirect_url ) );
$theme_editor_url = wp_parse_url( admin_url( 'theme-editor.php' ) );
if ( $theme_editor_url['path'] !== $url['path'] ) {
@@ -129,11 +129,11 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
) {
return $redirect_url;
}
- $theme = wp_get_theme( $query_params['theme'] );
+ $theme = wp_get_theme( $query_params['theme'] );
$theme_data = array(
- 'name' => $theme->get('Name'),
- 'version' => $theme->get('Version'),
- 'uri' => $theme->get( 'ThemeURI' ),
+ 'name' => $theme->get( 'Name' ),
+ 'version' => $theme->get( 'Version' ),
+ 'uri' => $theme->get( 'ThemeURI' ),
);
/**
@@ -204,9 +204,9 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
$allowed_files = array_merge( $allowed_files, $theme->get_files( 'php', -1 ) );
break;
case 'css':
- $style_files = $theme->get_files( 'css', -1 );
+ $style_files = $theme->get_files( 'css', -1 );
$allowed_files['style.css'] = $style_files['style.css'];
- $allowed_files = array_merge( $allowed_files, $style_files );
+ $allowed_files = array_merge( $allowed_files, $style_files );
break;
default:
$allowed_files = array_merge( $allowed_files, $theme->get_files( $type, -1 ) );
@@ -243,9 +243,9 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
fclose( $file_pointer );
$theme_data = array(
- 'name' => $theme->get('Name'),
- 'version' => $theme->get('Version'),
- 'uri' => $theme->get( 'ThemeURI' ),
+ 'name' => $theme->get( 'Name' ),
+ 'version' => $theme->get( 'Version' ),
+ 'uri' => $theme->get( 'ThemeURI' ),
);
/**
@@ -261,13 +261,13 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
return;
}
- $slug = $delete_theme_call['args'][0];
- $theme = wp_get_theme( $slug );
+ $slug = $delete_theme_call['args'][0];
+ $theme = wp_get_theme( $slug );
$theme_data = array(
- 'name' => $theme->get('Name'),
- 'version' => $theme->get('Version'),
- 'uri' => $theme->get( 'ThemeURI' ),
- 'slug' => $slug,
+ 'name' => $theme->get( 'Name' ),
+ 'version' => $theme->get( 'Version' ),
+ 'uri' => $theme->get( 'ThemeURI' ),
+ 'slug' => $slug,
);
/**
@@ -284,9 +284,9 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
public function check_upgrader( $upgrader, $details ) {
if ( ! isset( $details['type'] ) ||
- 'theme' !== $details['type'] ||
- is_wp_error( $upgrader->skin->result ) ||
- ! method_exists( $upgrader, 'theme_info' )
+ 'theme' !== $details['type'] ||
+ is_wp_error( $upgrader->skin->result ) ||
+ ! method_exists( $upgrader, 'theme_info' )
) {
return;
}
@@ -297,9 +297,9 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
return;
}
$theme_info = array(
- 'name' => $theme->get( 'Name' ),
+ 'name' => $theme->get( 'Name' ),
'version' => $theme->get( 'Version' ),
- 'uri' => $theme->get( 'ThemeURI' ),
+ 'uri' => $theme->get( 'ThemeURI' ),
);
/**
@@ -317,7 +317,7 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
if ( 'update' === $details['action'] ) {
$themes = array();
- if ( empty( $details['themes'] ) && isset ( $details['theme'] ) ) {
+ if ( empty( $details['themes'] ) && isset( $details['theme'] ) ) {
$details['themes'] = array( $details['theme'] );
}
@@ -329,9 +329,9 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
}
$themes[ $theme_slug ] = array(
- 'name' => $theme->get( 'Name' ),
- 'version' => $theme->get( 'Version' ),
- 'uri' => $theme->get( 'ThemeURI' ),
+ 'name' => $theme->get( 'Name' ),
+ 'version' => $theme->get( 'Version' ),
+ 'uri' => $theme->get( 'ThemeURI' ),
'stylesheet' => $theme->stylesheet,
);
}
@@ -358,11 +358,8 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
}
public function sync_theme_support( $new_name, $new_theme = null, $old_theme = null ) {
- // Previous theme support got added in WP 4.5
- $previous_theme = false;
- if ( $old_theme instanceof WP_Theme ) {
- $previous_theme = $this->get_theme_support_info( $old_theme );
- }
+ $previous_theme = $this->get_theme_support_info( $old_theme );
+
/**
* Fires when the client needs to sync theme support info
* Only sends theme support attributes whitelisted in Jetpack_Sync_Defaults::$default_theme_support_whitelist
@@ -372,7 +369,7 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
* @param array the theme support array
* @param array the previous theme since Jetpack 6.5.0
*/
- do_action( 'jetpack_sync_current_theme_support' , $this->get_theme_support_info(), $previous_theme );
+ do_action( 'jetpack_sync_current_theme_support', $this->get_theme_support_info(), $previous_theme );
}
public function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) {
@@ -421,16 +418,16 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
return array();
}
$moved_to_sidebar = array();
- $sidebar_name = $this->get_sidebar_name( $sidebar );
+ $sidebar_name = $this->get_sidebar_name( $sidebar );
- //Don't sync jetpack_widget_added if theme was switched
+ // Don't sync jetpack_widget_added if theme was switched
if ( $this->is_theme_switch() ) {
return array();
}
foreach ( $added_widgets as $added_widget ) {
$moved_to_sidebar[] = $added_widget;
- $added_widget_name = $this->get_widget_name( $added_widget );
+ $added_widget_name = $this->get_widget_name( $added_widget );
/**
* Helps Sync log that a widget got added
*
@@ -440,14 +437,13 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
* @param string $added_widget, Widget id got added
* @param string $sidebar_name, Sidebar id got changed Since 5.0.0
* @param string $added_widget_name, Widget id got added Since 5.0.0
- *
*/
- do_action( 'jetpack_widget_added', $sidebar, $added_widget, $sidebar_name, $added_widget_name );
+ do_action( 'jetpack_widget_added', $sidebar, $added_widget, $sidebar_name, $added_widget_name );
}
return $moved_to_sidebar;
}
- function sync_remove_widgets_from_sidebar( $new_widgets, $old_widgets, $sidebar, $inactive_widgets ) {
+ function sync_remove_widgets_from_sidebar( $new_widgets, $old_widgets, $sidebar, $inactive_widgets ) {
$removed_widgets = array_diff( $old_widgets, $new_widgets );
if ( empty( $removed_widgets ) ) {
@@ -455,9 +451,9 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
}
$moved_to_inactive = array();
- $sidebar_name = $this->get_sidebar_name( $sidebar );
+ $sidebar_name = $this->get_sidebar_name( $sidebar );
- foreach( $removed_widgets as $removed_widget ) {
+ foreach ( $removed_widgets as $removed_widget ) {
// Lets check if we didn't move the widget to in_active_widgets
if ( isset( $inactive_widgets ) && ! in_array( $removed_widget, $inactive_widgets ) ) {
$removed_widget_name = $this->get_widget_name( $removed_widget );
@@ -515,7 +511,7 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
}
$moved_to_inactive_ids = array();
- $moved_to_sidebar = array();
+ $moved_to_sidebar = array();
foreach ( $new_value as $sidebar => $new_widgets ) {
if ( in_array( $sidebar, array( 'array_version', 'wp_inactive_widgets' ) ) ) {
@@ -530,16 +526,16 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
}
$moved_to_inactive_recently = $this->sync_remove_widgets_from_sidebar( $new_widgets, $old_widgets, $sidebar, $new_value['wp_inactive_widgets'] );
- $moved_to_inactive_ids = array_merge( $moved_to_inactive_ids, $moved_to_inactive_recently );
+ $moved_to_inactive_ids = array_merge( $moved_to_inactive_ids, $moved_to_inactive_recently );
$moved_to_sidebar_recently = $this->sync_add_widgets_to_sidebar( $new_widgets, $old_widgets, $sidebar );
- $moved_to_sidebar = array_merge( $moved_to_sidebar, $moved_to_sidebar_recently );
+ $moved_to_sidebar = array_merge( $moved_to_sidebar, $moved_to_sidebar_recently );
$this->sync_widgets_reordered( $new_widgets, $old_widgets, $sidebar );
}
- //Don't sync either jetpack_widget_moved_to_inactive or jetpack_cleared_inactive_widgets if theme was switched
+ // Don't sync either jetpack_widget_moved_to_inactive or jetpack_cleared_inactive_widgets if theme was switched
if ( $this->is_theme_switch() ) {
return;
}
@@ -557,8 +553,8 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
*/
do_action( 'jetpack_widget_moved_to_inactive', $moved_to_inactive_ids, $moved_to_inactive_name );
} elseif ( empty( $moved_to_sidebar ) &&
- empty( $new_value['wp_inactive_widgets']) &&
- ! empty( $old_value['wp_inactive_widgets'] ) ) {
+ empty( $new_value['wp_inactive_widgets'] ) &&
+ ! empty( $old_value['wp_inactive_widgets'] ) ) {
/**
* Helps Sync log that a got cleared from inactive.
*
@@ -577,7 +573,7 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
global $_wp_theme_features;
$theme_support = array();
-
+
// We are trying to get the current theme info.
if ( $theme === null ) {
$theme = wp_get_theme();
@@ -590,16 +586,16 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
}
}
- $theme_support['name'] = $theme->get('Name');
- $theme_support['version'] = $theme->get('Version');
- $theme_support['slug'] = $theme->get_stylesheet();
- $theme_support['uri'] = $theme->get('ThemeURI');
+ $theme_support['name'] = $theme->get( 'Name' );
+ $theme_support['version'] = $theme->get( 'Version' );
+ $theme_support['slug'] = $theme->get_stylesheet();
+ $theme_support['uri'] = $theme->get( 'ThemeURI' );
return $theme_support;
}
private function get_delete_theme_call() {
- $backtrace = debug_backtrace();
+ $backtrace = debug_backtrace();
$delete_theme_call = null;
foreach ( $backtrace as $call ) {
if ( isset( $call['function'] ) && 'delete_theme' === $call['function'] ) {
@@ -613,4 +609,4 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module {
private function is_theme_switch() {
return did_action( 'after_switch_theme' );
}
-} \ No newline at end of file
+}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-updates.php b/plugins/jetpack/sync/class.jetpack-sync-module-updates.php
index 270f6a8d..4da4414f 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-updates.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-updates.php
@@ -5,6 +5,11 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module {
const UPDATES_CHECKSUM_OPTION_NAME = 'jetpack_updates_sync_checksum';
private $old_wp_version = null;
+ private $updates = array();
+
+ public function set_defaults() {
+ $this->updates = array();
+ }
function name() {
return 'updates';
@@ -21,20 +26,29 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module {
add_action( 'jetpack_update_themes_change', $callable );
add_action( 'jetpack_update_core_change', $callable );
- add_filter( 'jetpack_sync_before_enqueue_jetpack_update_plugins_change', array(
- $this,
- 'filter_update_keys',
- ), 10, 2 );
- add_filter( 'jetpack_sync_before_enqueue_upgrader_process_complete', array(
- $this,
- 'filter_upgrader_process_complete',
- ), 10, 2 );
+ add_filter(
+ 'jetpack_sync_before_enqueue_jetpack_update_plugins_change',
+ array(
+ $this,
+ 'filter_update_keys',
+ ),
+ 10,
+ 2
+ );
+ add_filter(
+ 'jetpack_sync_before_enqueue_upgrader_process_complete',
+ array(
+ $this,
+ 'filter_upgrader_process_complete',
+ ),
+ 10,
+ 2
+ );
add_action( 'automatic_updates_complete', $callable );
-
if ( is_multisite() ) {
- add_filter( 'pre_update_site_option_wpmu_upgrade_site', array ( $this, 'update_core_network_event' ), 10, 2 );
+ add_filter( 'pre_update_site_option_wpmu_upgrade_site', array( $this, 'update_core_network_event' ), 10, 2 );
add_action( 'jetpack_sync_core_update_network', $callable, 10, 3 );
}
@@ -65,7 +79,6 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module {
* @param int $wp_db_version the latest wp_db_version
* @param int $old_wp_db_version previous wp_db_version
* @param string $wp_version the latest wp_version
- *
*/
do_action( 'jetpack_sync_core_update_network', $wp_db_version, $old_wp_db_version, $wp_version );
return $wp_db_version;
@@ -74,7 +87,7 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module {
public function update_core( $new_wp_version ) {
global $pagenow;
- if ( isset( $_GET[ 'action' ] ) && 'do-core-reinstall' === $_GET[ 'action' ] ) {
+ if ( isset( $_GET['action'] ) && 'do-core-reinstall' === $_GET['action'] ) {
/**
* Sync event that fires when core reinstall was successful
*
@@ -115,9 +128,8 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module {
}
-
public function get_update_checksum( $update, $transient ) {
- $updates = array();
+ $updates = array();
$no_updated = array();
switch ( $transient ) {
case 'update_plugins':
@@ -132,7 +144,7 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module {
$no_updated = array_keys( $update->no_update );
}
- if ( ! isset( $no_updated[ 'jetpack/jetpack.php' ] ) && isset( $updates[ 'jetpack/jetpack.php' ] ) ) {
+ if ( ! isset( $no_updated['jetpack/jetpack.php'] ) && isset( $updates['jetpack/jetpack.php'] ) ) {
return false;
}
@@ -154,7 +166,7 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module {
case 'update_core':
if ( ! empty( $update->updates ) && is_array( $update->updates ) ) {
foreach ( $update->updates as $response ) {
- if( ! empty( $response->response ) && $response->response === 'latest' ) {
+ if ( ! empty( $response->response ) && $response->response === 'latest' ) {
continue;
}
if ( ! empty( $response->response ) && isset( $response->packages->full ) ) {
@@ -163,7 +175,7 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module {
}
}
- if ( ! empty( $update->version_checked ) ) {
+ if ( ! empty( $update->version_checked ) ) {
$no_updated = $update->version_checked;
}
@@ -180,9 +192,9 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module {
}
public function validate_update_change( $value, $expiration, $transient ) {
-
$new_checksum = $this->get_update_checksum( $value, $transient );
- if ( false === $new_checksum ) {
+
+ if ( false === $new_checksum ) {
return;
}
@@ -195,18 +207,42 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module {
$checksums[ $transient ] = $new_checksum;
update_option( self::UPDATES_CHECKSUM_OPTION_NAME, $checksums );
- /**
- * jetpack_{$transient}_change
- * jetpack_update_plugins_change
- * jetpack_update_themes_change
- * jetpack_update_core_change
- *
- * @since 5.1.0
- *
- * @param array containing info that tells us what needs updating
- *
- */
- do_action( "jetpack_{$transient}_change", $value );
+ if ( 'update_core' === $transient ) {
+ /**
+ * jetpack_update_core_change
+ *
+ * @since 5.1.0
+ *
+ * @param array containing info that tells us what needs updating
+ */
+ do_action( 'jetpack_update_core_change', $value );
+ return;
+ }
+ if ( empty( $this->updates ) ) {
+ // lets add the shutdown method once and only when the updates move from empty to filled with something
+ add_action( 'shutdown', array( $this, 'sync_last_event' ), 9 );
+ }
+ if ( ! isset( $this->updates[ $transient ] ) ) {
+ $this->updates[ $transient ] = array();
+ }
+ $this->updates[ $transient ][] = $value;
+ }
+
+ public function sync_last_event() {
+ foreach ( $this->updates as $transient => $values ) {
+ $value = end( $values ); // only send over the last value
+ /**
+ * jetpack_{$transient}_change
+ * jetpack_update_plugins_change
+ * jetpack_update_themes_change
+ *
+ * @since 5.1.0
+ *
+ * @param array containing info that tells us what needs updating
+ */
+ do_action( "jetpack_{$transient}_change", $value );
+ }
+
}
public function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) {
@@ -273,7 +309,7 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module {
return $args;
}
foreach ( $args[0]->response as $stylesheet => &$theme_data ) {
- $theme = wp_get_theme( $stylesheet );
+ $theme = wp_get_theme( $stylesheet );
$theme_data['name'] = $theme->name;
}
return $args;
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-users.php b/plugins/jetpack/sync/class.jetpack-sync-module-users.php
index 0c3f8500..6fb08e98 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-users.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-users.php
@@ -26,13 +26,9 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module {
add_action( 'add_user_to_blog', array( $this, 'add_user_to_blog_handler' ) );
add_action( 'jetpack_sync_add_user', $callable, 10, 2 );
- add_action( 'jetpack_sync_add_user', array( $this, 'clear_flags' ), 11 );
add_action( 'jetpack_sync_register_user', $callable, 10, 2 );
- add_action( 'jetpack_sync_register_user', array( $this, 'clear_flags' ), 11 );
-
add_action( 'jetpack_sync_save_user', $callable, 10, 2 );
- add_action( 'jetpack_sync_save_user', array( $this, 'clear_flags' ), 11 );
add_action( 'jetpack_sync_user_locale', $callable, 10, 2 );
add_action( 'jetpack_sync_user_locale_delete', $callable, 10, 1 );
@@ -53,7 +49,11 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module {
add_action( 'deleted_user_meta', array( $this, 'maybe_save_user_meta' ), 10, 4 );
// user authentication
- add_action( 'wp_login', $callable, 10, 2 );
+ add_filter( 'authenticate', array( $this, 'authenticate_handler' ), 1000, 3 );
+ add_action( 'wp_login', array( $this, 'wp_login_handler' ), 10, 2 );
+
+ add_action( 'jetpack_wp_login', $callable, 10, 3 );
+
add_action( 'wp_logout', $callable, 10, 0 );
add_action( 'wp_masterbar_logout', $callable, 10, 0 );
@@ -69,8 +69,7 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module {
public function init_before_send() {
-
- add_filter( 'jetpack_sync_before_send_wp_login', array( $this, 'expand_login_username' ), 10, 1 );
+ add_filter( 'jetpack_sync_before_send_jetpack_wp_login', array( $this, 'expand_login_username' ), 10, 1 );
add_filter( 'jetpack_sync_before_send_wp_logout', array( $this, 'expand_logout_username' ), 10, 2 );
// full sync
@@ -103,7 +102,7 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module {
return null;
}
$user->allowed_mime_types = get_allowed_mime_types( $user );
- $user->allcaps = $this->get_real_user_capabilities( $user );
+ $user->allcaps = $this->get_real_user_capabilities( $user );
// Only set the user locale if it is different from the site local
if ( get_locale() !== get_user_locale( $user->ID ) ) {
@@ -118,8 +117,8 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module {
if ( is_wp_error( $user ) ) {
return $user_capabilities;
}
- foreach( Jetpack_Sync_Defaults::get_capabilities_whitelist() as $capability ) {
- if ( $user_has_capabilities = user_can( $user , $capability ) ) {
+ foreach ( Jetpack_Sync_Defaults::get_capabilities_whitelist() as $capability ) {
+ if ( $user_has_capabilities = user_can( $user, $capability ) ) {
$user_capabilities[ $capability ] = true;
}
}
@@ -144,15 +143,15 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module {
}
public function expand_login_username( $args ) {
- list( $login, $user ) = $args;
- $user = $this->sanitize_user( $user );
+ list( $login, $user, $flags ) = $args;
+ $user = $this->sanitize_user( $user );
- return array( $login, $user );
+ return array( $login, $user, $flags );
}
public function expand_logout_username( $args, $user_id ) {
- $user = get_userdata( $user_id );
- $user = $this->sanitize_user( $user );
+ $user = get_userdata( $user_id );
+ $user = $this->sanitize_user( $user );
$login = '';
if ( is_object( $user ) && is_object( $user->data ) ) {
@@ -166,6 +165,67 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module {
return array( $login, $user );
}
+ /**
+ * Additional processing is needed for wp_login so we introduce this wrapper
+ * handler.
+ *
+ * @param String $user_login the user login.
+ * @param WP_User $user the user object.
+ */
+ function wp_login_handler( $user_login, $user ) {
+ /**
+ * Fires when a user is logged into a site.
+ *
+ * @since 7.2.0
+ *
+ * @param Numeric $user_id The user ID.
+ * @param WP_User $user The User Object of the user that currently logged in
+ * @param Array $params Any Flags that have been added during login
+ */
+ do_action( 'jetpack_wp_login', $user->ID, $user, $this->get_flags( $user->ID ) );
+ $this->clear_flags( $user->ID );
+ }
+
+ /**
+ * A hook for the authenticate event that checks the password strength.
+ *
+ * @param WP_Error|WP_User $user the user object, or an error.
+ * @param String $username the username.
+ * @param Sting $password the password used to authenticate.
+ * @return WP_Error|WP_User the same object that was passed into the function.
+ */
+ public function authenticate_handler( $user, $username, $password ) {
+ // In case of cookie authentication we don't do anything here.
+ if ( empty( $password ) ) {
+ return $user;
+ }
+
+ // We are only interested in successful authentication events.
+ if ( is_wp_error( $user ) || ! ( $user instanceof WP_User ) ) {
+ return $user;
+ }
+
+ jetpack_require_lib( 'class.jetpack-password-checker' );
+ $password_checker = new Jetpack_Password_Checker( $user->ID );
+
+ $test_results = $password_checker->test( $password, true );
+
+ // If the password passes tests, we don't do anything.
+ if ( empty( $test_results['test_results']['failed'] ) ) {
+ return $user;
+ }
+
+ $this->add_flags(
+ $user->ID,
+ array(
+ 'warning' => 'The password failed at least one strength test.',
+ 'failures' => $test_results['test_results']['failed'],
+ )
+ );
+
+ return $user;
+ }
+
public function deleted_user_handler( $deleted_user_id, $reassigned_user_id = '' ) {
$is_multisite = is_multisite();
/**
@@ -197,6 +257,7 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module {
* @param object The WP_User object
*/
do_action( 'jetpack_sync_register_user', $user_id, $this->get_flags( $user_id ) );
+ $this->clear_flags( $user_id );
}
@@ -217,6 +278,7 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module {
* @param object The WP_User object
*/
do_action( 'jetpack_sync_add_user', $user_id, $this->get_flags( $user_id ) );
+ $this->clear_flags( $user_id );
}
function save_user_handler( $user_id, $old_user_data = null ) {
@@ -255,12 +317,19 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module {
* @param array state - New since 5.8.0
*/
do_action( 'jetpack_sync_save_user', $user_id, $this->get_flags( $user_id ) );
+ $this->clear_flags( $user_id );
}
function save_user_role_handler( $user_id, $role, $old_roles = null ) {
- $this->add_flags( $user_id, array( 'role_changed' => true, 'previous_role' => $old_roles ) );
+ $this->add_flags(
+ $user_id,
+ array(
+ 'role_changed' => true,
+ 'previous_role' => $old_roles,
+ )
+ );
- //The jetpack_sync_register_user payload is identical to jetpack_sync_save_user, don't send both
+ // The jetpack_sync_register_user payload is identical to jetpack_sync_save_user, don't send both
if ( $this->is_create_user() || $this->is_add_user_to_blog() ) {
return;
}
@@ -268,6 +337,7 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module {
* This action is documented already in this file
*/
do_action( 'jetpack_sync_save_user', $user_id, $this->get_flags( $user_id ) );
+ $this->clear_flags( $user_id );
}
function get_flags( $user_id ) {
@@ -365,14 +435,14 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module {
}
public function remove_user_from_blog_handler( $user_id, $blog_id ) {
- //User is removed on add, see https://github.com/WordPress/WordPress/blob/0401cee8b36df3def8e807dd766adc02b359dfaf/wp-includes/ms-functions.php#L2114
+ // User is removed on add, see https://github.com/WordPress/WordPress/blob/0401cee8b36df3def8e807dd766adc02b359dfaf/wp-includes/ms-functions.php#L2114
if ( $this->is_add_new_user_to_blog() ) {
return;
}
$reassigned_user_id = $this->get_reassigned_network_user_id();
- //Note that we are in the context of the blog the user is removed from, see https://github.com/WordPress/WordPress/blob/473e1ba73bc5c18c72d7f288447503713d518790/wp-includes/ms-functions.php#L233
+ // Note that we are in the context of the blog the user is removed from, see https://github.com/WordPress/WordPress/blob/473e1ba73bc5c18c72d7f288447503713d518790/wp-includes/ms-functions.php#L233
/**
* Fires when a user is removed from a blog on a multisite installation
*
@@ -393,7 +463,7 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module {
}
protected function is_delete_user() {
- return Jetpack::is_function_in_backtrace( array( 'wp_delete_user' , 'remove_user_from_blog' ) );
+ return Jetpack::is_function_in_backtrace( array( 'wp_delete_user', 'remove_user_from_blog' ) );
}
protected function is_create_user() {
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-woocommerce.php b/plugins/jetpack/sync/class.jetpack-sync-module-woocommerce.php
index 2b8ecbc4..962258a2 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-woocommerce.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-woocommerce.php
@@ -51,7 +51,7 @@ class Jetpack_Sync_Module_WooCommerce extends Jetpack_Sync_Module {
}
function name() {
- return "woocommerce";
+ return 'woocommerce';
}
public function init_listeners( $callable ) {
@@ -206,7 +206,7 @@ class Jetpack_Sync_Module_WooCommerce extends Jetpack_Sync_Module {
);
private static $wc_constants_whitelist = array(
- //woocommerce options
+ // woocommerce options
'WC_PLUGIN_FILE',
'WC_ABSPATH',
'WC_PLUGIN_BASENAME',
@@ -222,7 +222,7 @@ class Jetpack_Sync_Module_WooCommerce extends Jetpack_Sync_Module {
);
private static $wc_post_meta_whitelist = array(
- //woocommerce products
+ // woocommerce products
// https://github.com/woocommerce/woocommerce/blob/8ed6e7436ff87c2153ed30edd83c1ab8abbdd3e9/includes/data-stores/class-wc-product-data-store-cpt.php#L21
'_visibility',
'_sku',
@@ -262,7 +262,7 @@ class Jetpack_Sync_Module_WooCommerce extends Jetpack_Sync_Module {
'_product_version',
'_wp_old_slug',
- //woocommerce orders
+ // woocommerce orders
// https://github.com/woocommerce/woocommerce/blob/8ed6e7436ff87c2153ed30edd83c1ab8abbdd3e9/includes/data-stores/class-wc-order-data-store-cpt.php#L27
'_order_key',
'_order_currency',
@@ -314,7 +314,7 @@ class Jetpack_Sync_Module_WooCommerce extends Jetpack_Sync_Module {
// https://github.com/woocommerce/woocommerce/blob/8ed6e7436ff87c2153ed30edd83c1ab8abbdd3e9/includes/data-stores/class-wc-order-data-store-cpt.php#L594
'_order_stock_reduced',
- //woocommerce order refunds
+ // woocommerce order refunds
// https://github.com/woocommerce/woocommerce/blob/b8a2815ae546c836467008739e7ff5150cb08e93/includes/data-stores/class-wc-order-refund-data-store-cpt.php#L20
'_order_currency',
'_refund_amount',
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-wp-super-cache.php b/plugins/jetpack/sync/class.jetpack-sync-module-wp-super-cache.php
index f1c9fc80..04d6c5dd 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module-wp-super-cache.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module-wp-super-cache.php
@@ -46,26 +46,26 @@ class Jetpack_Sync_Module_WP_Super_Cache extends Jetpack_Sync_Module {
global $cache_domain_mapping;
return array(
- 'wp_cache_mod_rewrite' => $wp_cache_mod_rewrite,
- 'cache_enabled' => $cache_enabled,
- 'super_cache_enabled' => $super_cache_enabled,
- 'ossdlcdn' => $ossdlcdn,
- 'cache_rebuild_files' => $cache_rebuild_files,
- 'wp_cache_mobile' => $wp_cache_mobile,
- 'wp_super_cache_late_init' => $wp_super_cache_late_init,
- 'wp_cache_anon_only' => $wp_cache_anon_only,
- 'wp_cache_not_logged_in' => $wp_cache_not_logged_in,
- 'wp_cache_clear_on_post_edit' => $wp_cache_clear_on_post_edit,
- 'wp_cache_mobile_enabled' => $wp_cache_mobile_enabled,
- 'wp_super_cache_debug' => $wp_super_cache_debug,
- 'cache_max_time' => $cache_max_time,
+ 'wp_cache_mod_rewrite' => $wp_cache_mod_rewrite,
+ 'cache_enabled' => $cache_enabled,
+ 'super_cache_enabled' => $super_cache_enabled,
+ 'ossdlcdn' => $ossdlcdn,
+ 'cache_rebuild_files' => $cache_rebuild_files,
+ 'wp_cache_mobile' => $wp_cache_mobile,
+ 'wp_super_cache_late_init' => $wp_super_cache_late_init,
+ 'wp_cache_anon_only' => $wp_cache_anon_only,
+ 'wp_cache_not_logged_in' => $wp_cache_not_logged_in,
+ 'wp_cache_clear_on_post_edit' => $wp_cache_clear_on_post_edit,
+ 'wp_cache_mobile_enabled' => $wp_cache_mobile_enabled,
+ 'wp_super_cache_debug' => $wp_super_cache_debug,
+ 'cache_max_time' => $cache_max_time,
'wp_cache_refresh_single_only' => $wp_cache_refresh_single_only,
- 'wp_cache_mfunc_enabled' => $wp_cache_mfunc_enabled,
- 'wp_supercache_304' => $wp_supercache_304,
- 'wp_cache_no_cache_for_get' => $wp_cache_no_cache_for_get,
- 'wp_cache_mutex_disabled' => $wp_cache_mutex_disabled,
- 'cache_jetpack' => $cache_jetpack,
- 'cache_domain_mapping' => $cache_domain_mapping,
+ 'wp_cache_mfunc_enabled' => $wp_cache_mfunc_enabled,
+ 'wp_supercache_304' => $wp_supercache_304,
+ 'wp_cache_no_cache_for_get' => $wp_cache_no_cache_for_get,
+ 'wp_cache_mutex_disabled' => $wp_cache_mutex_disabled,
+ 'cache_jetpack' => $cache_jetpack,
+ 'cache_domain_mapping' => $cache_domain_mapping,
);
}
@@ -76,4 +76,4 @@ class Jetpack_Sync_Module_WP_Super_Cache extends Jetpack_Sync_Module {
public function add_wp_super_cache_callable_whitelist( $list ) {
return array_merge( $list, self::$wp_super_cache_callables );
}
-} \ No newline at end of file
+}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-module.php b/plugins/jetpack/sync/class.jetpack-sync-module.php
index ed9ef753..619b36d7 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-module.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-module.php
@@ -65,11 +65,11 @@ abstract class Jetpack_Sync_Module {
$where_sql = '1 = 1';
}
- $items_per_page = 1000;
- $page = 1;
- $chunk_count = 0;
- $previous_max_id = $state ? $state : '~0';
- $listener = Jetpack_Sync_Listener::get_instance();
+ $items_per_page = 1000;
+ $page = 1;
+ $chunk_count = 0;
+ $previous_max_id = $state ? $state : '~0';
+ $listener = Jetpack_Sync_Listener::get_instance();
// count down from max_id to min_id so we get newest posts/comments/etc first
while ( $ids = $wpdb->get_col( "SELECT {$id_field} FROM {$table_name} WHERE {$where_sql} AND {$id_field} < {$previous_max_id} ORDER BY {$id_field} DESC LIMIT {$items_per_page}" ) ) {
@@ -79,7 +79,7 @@ abstract class Jetpack_Sync_Module {
// if we hit our row limit, process and return
if ( $chunk_count + count( $chunked_ids ) >= $max_items_to_enqueue ) {
$remaining_items_count = $max_items_to_enqueue - $chunk_count;
- $remaining_items = array_slice( $chunked_ids, 0, $remaining_items_count );
+ $remaining_items = array_slice( $chunked_ids, 0, $remaining_items_count );
$listener->bulk_enqueue_full_sync_actions( $action_name, $remaining_items );
@@ -89,8 +89,8 @@ abstract class Jetpack_Sync_Module {
$listener->bulk_enqueue_full_sync_actions( $action_name, $chunked_ids );
- $chunk_count += count( $chunked_ids );
- $page += 1;
+ $chunk_count += count( $chunked_ids );
+ $page += 1;
$previous_max_id = end( $ids );
}
@@ -110,9 +110,10 @@ abstract class Jetpack_Sync_Module {
return array_map(
array( $this, 'unserialize_meta' ),
$wpdb->get_results(
- "SELECT $id, meta_key, meta_value, meta_id FROM $table WHERE $id IN ( " . implode( ',', wp_parse_id_list( $ids ) ) . ' )'.
- " AND meta_key IN ( $private_meta_whitelist_sql ) "
- , OBJECT )
+ "SELECT $id, meta_key, meta_value, meta_id FROM $table WHERE $id IN ( " . implode( ',', wp_parse_id_list( $ids ) ) . ' )' .
+ " AND meta_key IN ( $private_meta_whitelist_sql ) ",
+ OBJECT
+ )
);
}
@@ -145,7 +146,7 @@ abstract class Jetpack_Sync_Module {
}
$objects = array();
- foreach( (array) $ids as $id ) {
+ foreach ( (array) $ids as $id ) {
$object = $this->get_object_by_id( $object_type, $id );
// Only add object if we have the object.
diff --git a/plugins/jetpack/sync/class.jetpack-sync-modules.php b/plugins/jetpack/sync/class.jetpack-sync-modules.php
index b993e062..2450bae9 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-modules.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-modules.php
@@ -90,7 +90,7 @@ class Jetpack_Sync_Modules {
}
static function load_module( $module_name ) {
- return new $module_name;
+ return new $module_name();
}
static function set_module_defaults( $module ) {
diff --git a/plugins/jetpack/sync/class.jetpack-sync-queue.php b/plugins/jetpack/sync/class.jetpack-sync-queue.php
index 6b012171..ae40a597 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-queue.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-queue.php
@@ -38,7 +38,7 @@ class Jetpack_Sync_Queue {
function __construct( $id ) {
$this->id = str_replace( '-', '_', $id ); // necessary to ensure we don't have ID collisions in the SQL
$this->row_iterator = 0;
- $this->random_int = mt_rand( 1, 1000000 );
+ $this->random_int = mt_rand( 1, 1000000 );
}
function add( $item ) {
@@ -47,12 +47,14 @@ class Jetpack_Sync_Queue {
// this basically tries to add the option until enough time has elapsed that
// it has a unique (microtime-based) option key
while ( ! $added ) {
- $rows_added = $wpdb->query( $wpdb->prepare(
- "INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES (%s, %s,%s)",
- $this->get_next_data_row_option_name(),
- serialize( $item ),
- 'no'
- ) );
+ $rows_added = $wpdb->query(
+ $wpdb->prepare(
+ "INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES (%s, %s,%s)",
+ $this->get_next_data_row_option_name(),
+ serialize( $item ),
+ 'no'
+ )
+ );
$added = ( 0 !== $rows_added );
}
}
@@ -94,10 +96,12 @@ class Jetpack_Sync_Queue {
function lag( $now = null ) {
global $wpdb;
- $first_item_name = $wpdb->get_var( $wpdb->prepare(
- "SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_name ASC LIMIT 1",
- "jpsq_{$this->id}-%"
- ) );
+ $first_item_name = $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_name ASC LIMIT 1",
+ "jpsq_{$this->id}-%"
+ )
+ );
if ( ! $first_item_name ) {
return 0;
@@ -119,25 +123,34 @@ class Jetpack_Sync_Queue {
function reset() {
global $wpdb;
$this->delete_checkout_id();
- $wpdb->query( $wpdb->prepare(
- "DELETE FROM $wpdb->options WHERE option_name LIKE %s", "jpsq_{$this->id}-%"
- ) );
+ $wpdb->query(
+ $wpdb->prepare(
+ "DELETE FROM $wpdb->options WHERE option_name LIKE %s",
+ "jpsq_{$this->id}-%"
+ )
+ );
}
function size() {
global $wpdb;
- return (int) $wpdb->get_var( $wpdb->prepare(
- "SELECT count(*) FROM $wpdb->options WHERE option_name LIKE %s", "jpsq_{$this->id}-%"
- ) );
+ return (int) $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT count(*) FROM $wpdb->options WHERE option_name LIKE %s",
+ "jpsq_{$this->id}-%"
+ )
+ );
}
// we use this peculiar implementation because it's much faster than count(*)
function has_any_items() {
global $wpdb;
- $value = $wpdb->get_var( $wpdb->prepare(
- "SELECT exists( SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s )", "jpsq_{$this->id}-%"
- ) );
+ $value = $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT exists( SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s )",
+ "jpsq_{$this->id}-%"
+ )
+ );
return ( $value === '1' );
}
@@ -216,7 +229,7 @@ class Jetpack_Sync_Queue {
$max_item_id = $item_with_size->id;
}
- $query = $wpdb->prepare(
+ $query = $wpdb->prepare(
"SELECT option_name AS id, option_value AS value FROM $wpdb->options WHERE option_name >= %s and option_name <= %s ORDER BY option_name ASC",
$min_item_id,
$max_item_id
@@ -337,9 +350,9 @@ class Jetpack_Sync_Queue {
private function get_checkout_id() {
global $wpdb;
- $checkout_value = $wpdb->get_var(
+ $checkout_value = $wpdb->get_var(
$wpdb->prepare(
- "SELECT option_value FROM $wpdb->options WHERE option_name = %s",
+ "SELECT option_value FROM $wpdb->options WHERE option_name = %s",
$this->get_lock_option_name()
)
);
@@ -357,10 +370,10 @@ class Jetpack_Sync_Queue {
private function set_checkout_id( $checkout_id ) {
global $wpdb;
- $expires = time() + Jetpack_Sync_Defaults::$default_sync_queue_lock_timeout;
+ $expires = time() + Jetpack_Sync_Defaults::$default_sync_queue_lock_timeout;
$updated_num = $wpdb->query(
$wpdb->prepare(
- "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s",
+ "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s",
"$checkout_id:$expires",
$this->get_lock_option_name()
)
@@ -369,7 +382,7 @@ class Jetpack_Sync_Queue {
if ( ! $updated_num ) {
$updated_num = $wpdb->query(
$wpdb->prepare(
- "INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, 'no' )",
+ "INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, 'no' )",
$this->get_lock_option_name(),
"$checkout_id:$expires"
)
@@ -383,11 +396,11 @@ class Jetpack_Sync_Queue {
global $wpdb;
// rather than delete, which causes fragmentation, we update in place
return $wpdb->query(
- $wpdb->prepare(
- "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s",
- "0:0",
- $this->get_lock_option_name()
- )
+ $wpdb->prepare(
+ "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s",
+ '0:0',
+ $this->get_lock_option_name()
+ )
);
}
@@ -455,11 +468,11 @@ class Jetpack_Sync_Utils {
return array_map( array( __CLASS__, 'get_item_id' ), $items );
}
- static private function get_item_value( $item ) {
+ private static function get_item_value( $item ) {
return $item->value;
}
- static private function get_item_id( $item ) {
+ private static function get_item_id( $item ) {
return $item->id;
}
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-sender.php b/plugins/jetpack/sync/class.jetpack-sync-sender.php
index 4a5b678e..21f91481 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-sender.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-sender.php
@@ -13,8 +13,8 @@ require_once dirname( __FILE__ ) . '/class.jetpack-sync-settings.php';
class Jetpack_Sync_Sender {
const NEXT_SYNC_TIME_OPTION_NAME = 'jetpack_next_sync_time';
- const WPCOM_ERROR_SYNC_DELAY = 60;
- const QUEUE_LOCKED_SYNC_DELAY = 10;
+ const WPCOM_ERROR_SYNC_DELAY = 60;
+ const QUEUE_LOCKED_SYNC_DELAY = 10;
private $dequeue_max_bytes;
private $upload_max_bytes;
@@ -53,14 +53,14 @@ class Jetpack_Sync_Sender {
}
}
- public function maybe_set_user_from_token( ) {
- $jetpack = Jetpack::init();
+ public function maybe_set_user_from_token() {
+ $jetpack = Jetpack::init();
$verified_user = $jetpack->verify_xml_rpc_signature();
if ( Jetpack_Constants::is_true( 'XMLRPC_REQUEST' ) &&
! is_wp_error( $verified_user )
&& $verified_user
) {
- $old_user = wp_get_current_user();
+ $old_user = wp_get_current_user();
$this->old_user = isset( $old_user->ID ) ? $old_user->ID : 0;
wp_set_current_user( $verified_user['user_id'] );
}
@@ -73,7 +73,7 @@ class Jetpack_Sync_Sender {
}
public function get_next_sync_time( $queue_name ) {
- return (double) get_option( self::NEXT_SYNC_TIME_OPTION_NAME . '_' . $queue_name, 0 );
+ return (float) get_option( self::NEXT_SYNC_TIME_OPTION_NAME . '_' . $queue_name, 0 );
}
public function set_next_sync_time( $time, $queue_name ) {
@@ -125,7 +125,7 @@ class Jetpack_Sync_Sender {
Jetpack_Sync_Settings::set_is_syncing( false );
- $exceeded_sync_wait_threshold = ( microtime( true ) - $start_time ) > (double) $this->get_sync_wait_threshold();
+ $exceeded_sync_wait_threshold = ( microtime( true ) - $start_time ) > (float) $this->get_sync_wait_threshold();
if ( is_wp_error( $sync_result ) ) {
if ( 'unclosed_buffer' === $sync_result->get_error_code() ) {
@@ -144,13 +144,13 @@ class Jetpack_Sync_Sender {
public function get_items_to_send( $buffer, $encode = true ) {
// track how long we've been processing so we can avoid request timeouts
- $start_time = microtime( true );
+ $start_time = microtime( true );
$upload_size = 0;
$items_to_send = array();
$items = $buffer->get_items();
// set up current screen to avoid errors rendering content
- require_once( ABSPATH . 'wp-admin/includes/class-wp-screen.php' );
- require_once( ABSPATH . 'wp-admin/includes/screen.php' );
+ require_once ABSPATH . 'wp-admin/includes/class-wp-screen.php';
+ require_once ABSPATH . 'wp-admin/includes/screen.php';
set_current_screen( 'sync' );
$skipped_items_ids = array();
// we estimate the total encoded size as we go by encoding each item individually
@@ -180,7 +180,7 @@ class Jetpack_Sync_Sender {
break;
}
$items_to_send[ $key ] = $encoded_item;
- if ( microtime(true) - $start_time > $this->max_dequeue_time ) {
+ if ( microtime( true ) - $start_time > $this->max_dequeue_time ) {
break;
}
}
@@ -188,8 +188,13 @@ class Jetpack_Sync_Sender {
return array( $items_to_send, $skipped_items_ids, $items, microtime( true ) - $start_time );
}
- public function do_sync_for_queue( $queue ) {
+ private function fastcgi_finish_request() {
+ if ( function_exists( 'fastcgi_finish_request' ) && version_compare( phpversion(), '7.0.16', '>=' ) ) {
+ fastcgi_finish_request();
+ }
+ }
+ public function do_sync_for_queue( $queue ) {
do_action( 'jetpack_sync_before_send_queue_' . $queue->id );
if ( $queue->size() === 0 ) {
return new WP_Error( 'empty_queue_' . $queue->id );
@@ -201,6 +206,11 @@ class Jetpack_Sync_Sender {
ignore_user_abort( true );
}
+ /* Don't make the request block till we finish, if possible. */
+ if ( Jetpack_Constants::is_true( 'REST_REQUEST' ) || Jetpack_Constants::is_true('XMLRPC_REQUEST' ) ) {
+ $this->fastcgi_finish_request();
+ }
+
$checkout_start_time = microtime( true );
$buffer = $queue->checkout_with_memory_limit( $this->dequeue_max_bytes, $this->upload_max_rows );
@@ -235,7 +245,7 @@ class Jetpack_Sync_Sender {
Jetpack_Sync_Settings::set_is_sending( false );
} else {
$processed_item_ids = $skipped_items_ids;
- $skipped_items_ids = array();
+ $skipped_items_ids = array();
}
if ( ! $processed_item_ids || is_wp_error( $processed_item_ids ) ) {
@@ -293,9 +303,9 @@ class Jetpack_Sync_Sender {
}
function set_codec() {
if ( function_exists( 'gzinflate' ) ) {
- $this->codec = new Jetpack_Sync_JSON_Deflate_Array_Codec();
+ $this->codec = new Jetpack_Sync_JSON_Deflate_Array_Codec();
} else {
- $this->codec = new Jetpack_Sync_Simple_Codec();
+ $this->codec = new Jetpack_Sync_Simple_Codec();
}
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-server.php b/plugins/jetpack/sync/class.jetpack-sync-server.php
index 321fd0f0..dbd9172a 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-server.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-server.php
@@ -9,8 +9,8 @@ require_once dirname( __FILE__ ) . '/class.jetpack-sync-json-deflate-array-codec
class Jetpack_Sync_Server {
private $codec;
const MAX_TIME_PER_REQUEST_IN_SECONDS = 15;
- const BLOG_LOCK_TRANSIENT_PREFIX = 'jp_sync_req_lock_';
- const BLOG_LOCK_TRANSIENT_EXPIRY = 60; // seconds
+ const BLOG_LOCK_TRANSIENT_PREFIX = 'jp_sync_req_lock_';
+ const BLOG_LOCK_TRANSIENT_EXPIRY = 60; // seconds
// this is necessary because you can't use "new" when you declare instance properties >:(
function __construct() {
diff --git a/plugins/jetpack/sync/class.jetpack-sync-settings.php b/plugins/jetpack/sync/class.jetpack-sync-settings.php
index 3f0a1fee..c581a7dd 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-settings.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-settings.php
@@ -6,24 +6,24 @@ class Jetpack_Sync_Settings {
const SETTINGS_OPTION_PREFIX = 'jetpack_sync_settings_';
static $valid_settings = array(
- 'dequeue_max_bytes' => true,
- 'upload_max_bytes' => true,
- 'upload_max_rows' => true,
- 'sync_wait_time' => true,
- 'sync_wait_threshold' => true,
- 'enqueue_wait_time' => true,
- 'max_queue_size' => true,
- 'max_queue_lag' => true,
- 'queue_max_writes_sec' => true,
- 'post_types_blacklist' => true,
- 'disable' => true,
- 'render_filtered_content' => true,
- 'post_meta_whitelist' => true,
- 'comment_meta_whitelist' => true,
- 'max_enqueue_full_sync' => true,
- 'max_queue_size_full_sync'=> true,
- 'sync_via_cron' => true,
- 'cron_sync_time_limit' => true,
+ 'dequeue_max_bytes' => true,
+ 'upload_max_bytes' => true,
+ 'upload_max_rows' => true,
+ 'sync_wait_time' => true,
+ 'sync_wait_threshold' => true,
+ 'enqueue_wait_time' => true,
+ 'max_queue_size' => true,
+ 'max_queue_lag' => true,
+ 'queue_max_writes_sec' => true,
+ 'post_types_blacklist' => true,
+ 'disable' => true,
+ 'render_filtered_content' => true,
+ 'post_meta_whitelist' => true,
+ 'comment_meta_whitelist' => true,
+ 'max_enqueue_full_sync' => true,
+ 'max_queue_size_full_sync' => true,
+ 'sync_via_cron' => true,
+ 'cron_sync_time_limit' => true,
);
static $is_importing;
@@ -65,7 +65,7 @@ class Jetpack_Sync_Settings {
$value = intval( $value );
}
$default_array_value = null;
- switch( $setting ) {
+ switch ( $setting ) {
case 'post_types_blacklist':
$default_array_value = Jetpack_Sync_Defaults::$blacklisted_post_types;
break;
@@ -97,7 +97,7 @@ class Jetpack_Sync_Settings {
unset( self::$settings_cache[ $setting ] );
// if we set the disabled option to true, clear the queues
- if ( 'disable' === $setting && !! $value ) {
+ if ( 'disable' === $setting && ! ! $value ) {
require_once dirname( __FILE__ ) . '/class.jetpack-sync-listener.php';
$listener = Jetpack_Sync_Listener::get_instance();
$listener->get_sync_queue()->reset();
@@ -136,7 +136,7 @@ class Jetpack_Sync_Settings {
}
static function set_importing( $is_importing ) {
- // set to NULL to revert to WP_IMPORTING, the standard behaviour
+ // set to NULL to revert to WP_IMPORTING, the standard behavior
self::$is_importing = $is_importing;
}
@@ -149,7 +149,7 @@ class Jetpack_Sync_Settings {
}
static function set_doing_cron( $is_doing_cron ) {
- // set to NULL to revert to WP_IMPORTING, the standard behaviour
+ // set to NULL to revert to WP_IMPORTING, the standard behavior
self::$is_doing_cron = $is_doing_cron;
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-simple-codec.php b/plugins/jetpack/sync/class.jetpack-sync-simple-codec.php
index 622f4bea..7bd9aaac 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-simple-codec.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-simple-codec.php
@@ -7,7 +7,7 @@ require_once dirname( __FILE__ ) . '/class.jetpack-sync-json-deflate-array-codec
* algorithm to compress objects serialized using json_encode
*/
class Jetpack_Sync_Simple_Codec extends Jetpack_Sync_JSON_Deflate_Array_Codec {
- const CODEC_NAME = "simple";
+ const CODEC_NAME = 'simple';
public function name() {
return self::CODEC_NAME;
diff --git a/plugins/jetpack/sync/class.jetpack-sync-users.php b/plugins/jetpack/sync/class.jetpack-sync-users.php
index 414eda3a..de032e2d 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-users.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-users.php
@@ -21,7 +21,7 @@ class Jetpack_Sync_Users {
static function user_role_change( $user_id ) {
if ( Jetpack::is_user_connected( $user_id ) ) {
self::update_role_on_com( $user_id );
- //try to choose a new master if we're demoting the current one
+ // try to choose a new master if we're demoting the current one
self::maybe_demote_master_user( $user_id );
}
}
diff --git a/plugins/jetpack/sync/class.jetpack-sync-wp-replicastore.php b/plugins/jetpack/sync/class.jetpack-sync-wp-replicastore.php
index bf5fe982..2b24caf6 100644
--- a/plugins/jetpack/sync/class.jetpack-sync-wp-replicastore.php
+++ b/plugins/jetpack/sync/class.jetpack-sync-wp-replicastore.php
@@ -64,7 +64,10 @@ class Jetpack_Sync_WP_Replicastore implements iJetpack_Sync_Replicastore {
// TODO: actually use max_id/min_id
public function get_posts( $status = null, $min_id = null, $max_id = null ) {
- $args = array( 'orderby' => 'ID', 'posts_per_page' => -1 );
+ $args = array(
+ 'orderby' => 'ID',
+ 'posts_per_page' => -1,
+ );
if ( $status ) {
$args['post_status'] = $status;
@@ -145,12 +148,12 @@ class Jetpack_Sync_WP_Replicastore implements iJetpack_Sync_Replicastore {
public function posts_checksum( $min_id = null, $max_id = null ) {
global $wpdb;
- return $this->table_checksum( $wpdb->posts, Jetpack_Sync_Defaults::$default_post_checksum_columns , 'ID', Jetpack_Sync_Settings::get_blacklisted_post_types_sql(), $min_id, $max_id );
+ return $this->table_checksum( $wpdb->posts, Jetpack_Sync_Defaults::$default_post_checksum_columns, 'ID', Jetpack_Sync_Settings::get_blacklisted_post_types_sql(), $min_id, $max_id );
}
public function post_meta_checksum( $min_id = null, $max_id = null ) {
global $wpdb;
- return $this->table_checksum( $wpdb->postmeta, Jetpack_Sync_Defaults::$default_post_meta_checksum_columns , 'meta_id', Jetpack_Sync_Settings::get_whitelisted_post_meta_sql(), $min_id, $max_id );
+ return $this->table_checksum( $wpdb->postmeta, Jetpack_Sync_Defaults::$default_post_meta_checksum_columns, 'meta_id', Jetpack_Sync_Settings::get_whitelisted_post_meta_sql(), $min_id, $max_id );
}
public function comment_count( $status = null, $min_id = null, $max_id = null ) {
@@ -196,7 +199,10 @@ class Jetpack_Sync_WP_Replicastore implements iJetpack_Sync_Replicastore {
// TODO: actually use max_id/min_id
public function get_comments( $status = null, $min_id = null, $max_id = null ) {
- $args = array( 'orderby' => 'ID', 'status' => 'all' );
+ $args = array(
+ 'orderby' => 'ID',
+ 'status' => 'all',
+ );
if ( $status ) {
$args['status'] = $status;
@@ -210,14 +216,9 @@ class Jetpack_Sync_WP_Replicastore implements iJetpack_Sync_Replicastore {
}
public function upsert_comment( $comment ) {
- global $wpdb, $wp_version;
+ global $wpdb;
- if ( version_compare( $wp_version, '4.4', '<' ) ) {
- $comment = (array) $comment;
- } else {
- // WP 4.4 introduced the WP_Comment Class
- $comment = $comment->to_array();
- }
+ $comment = $comment->to_array();
// filter by fields on comment table
$comment_fields_whitelist = array(
@@ -287,14 +288,14 @@ class Jetpack_Sync_WP_Replicastore implements iJetpack_Sync_Replicastore {
public function comment_meta_checksum( $min_id = null, $max_id = null ) {
global $wpdb;
- return $this->table_checksum( $wpdb->commentmeta, Jetpack_Sync_Defaults::$default_comment_meta_checksum_columns , 'meta_id', Jetpack_Sync_Settings::get_whitelisted_comment_meta_sql(), $min_id, $max_id );
+ return $this->table_checksum( $wpdb->commentmeta, Jetpack_Sync_Defaults::$default_comment_meta_checksum_columns, 'meta_id', Jetpack_Sync_Settings::get_whitelisted_comment_meta_sql(), $min_id, $max_id );
}
public function options_checksum() {
global $wpdb;
$options_whitelist = "'" . implode( "', '", Jetpack_Sync_Defaults::$default_options_whitelist ) . "'";
- $where_sql = "option_name IN ( $options_whitelist )";
+ $where_sql = "option_name IN ( $options_whitelist )";
return $this->table_checksum( $wpdb->options, Jetpack_Sync_Defaults::$default_option_checksum_columns, null, $where_sql, null, null );
}
@@ -345,24 +346,33 @@ class Jetpack_Sync_WP_Replicastore implements iJetpack_Sync_Replicastore {
global $wpdb;
- $exists = $wpdb->get_var( $wpdb->prepare(
- "SELECT EXISTS( SELECT 1 FROM $table WHERE meta_id = %d )",
- $meta_id
- ) );
+ $exists = $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT EXISTS( SELECT 1 FROM $table WHERE meta_id = %d )",
+ $meta_id
+ )
+ );
if ( $exists ) {
- $wpdb->update( $table, array(
- 'meta_key' => $meta_key,
- 'meta_value' => maybe_serialize( $meta_value ),
- ), array( 'meta_id' => $meta_id ) );
+ $wpdb->update(
+ $table,
+ array(
+ 'meta_key' => $meta_key,
+ 'meta_value' => maybe_serialize( $meta_value ),
+ ),
+ array( 'meta_id' => $meta_id )
+ );
} else {
$object_id_field = $type . '_id';
- $wpdb->insert( $table, array(
- 'meta_id' => $meta_id,
- $object_id_field => $object_id,
- 'meta_key' => $meta_key,
- 'meta_value' => maybe_serialize( $meta_value ),
- ) );
+ $wpdb->insert(
+ $table,
+ array(
+ 'meta_id' => $meta_id,
+ $object_id_field => $object_id,
+ 'meta_key' => $meta_key,
+ 'meta_value' => maybe_serialize( $meta_value ),
+ )
+ );
}
wp_cache_delete( $object_id, $type . '_meta' );
@@ -396,8 +406,8 @@ class Jetpack_Sync_WP_Replicastore implements iJetpack_Sync_Replicastore {
if ( ! $table ) {
return false;
}
- $column = sanitize_key($type . '_id' );
- $wpdb->query( $wpdb->prepare( "DELETE FROM $table WHERE $column IN (%s) && meta_key = %s", implode( ',', $object_ids ), $meta_key ) );
+ $column = sanitize_key( $type . '_id' );
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $table WHERE $column IN (%s) && meta_key = %s", implode( ',', $object_ids ), $meta_key ) );
// if we don't have an object ID what do we do - invalidate ALL meta?
foreach ( $object_ids as $object_id ) {
@@ -506,10 +516,12 @@ class Jetpack_Sync_WP_Replicastore implements iJetpack_Sync_Replicastore {
public function update_term( $term_object ) {
$taxonomy = $term_object->taxonomy;
global $wpdb;
- $exists = $wpdb->get_var( $wpdb->prepare(
- "SELECT EXISTS( SELECT 1 FROM $wpdb->terms WHERE term_id = %d )",
- $term_object->term_id
- ) );
+ $exists = $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT EXISTS( SELECT 1 FROM $wpdb->terms WHERE term_id = %d )",
+ $term_object->term_id
+ )
+ );
if ( ! $exists ) {
$term_object = sanitize_term( clone( $term_object ), $taxonomy, 'db' );
$term = array(
@@ -555,7 +567,7 @@ class Jetpack_Sync_WP_Replicastore implements iJetpack_Sync_Replicastore {
$term = get_term_by( 'term_taxonomy_id', $tt_id );
$taxonomies[ $term->taxonomy ][] = $tt_id;
}
- $in_tt_ids = implode( ", ", $tt_ids_sanitized );
+ $in_tt_ids = implode( ', ', $tt_ids_sanitized );
/**
* Fires immediately before an object-term relationship is deleted.
@@ -622,14 +634,14 @@ class Jetpack_Sync_WP_Replicastore implements iJetpack_Sync_Replicastore {
}
public function checksum_all() {
- $post_meta_checksum = $this->checksum_histogram( 'post_meta', 1 );
+ $post_meta_checksum = $this->checksum_histogram( 'post_meta', 1 );
$comment_meta_checksum = $this->checksum_histogram( 'comment_meta', 1 );
return array(
- 'posts' => $this->posts_checksum(),
- 'comments' => $this->comments_checksum(),
- 'post_meta'=> reset( $post_meta_checksum ),
- 'comment_meta'=> reset( $comment_meta_checksum ),
+ 'posts' => $this->posts_checksum(),
+ 'comments' => $this->comments_checksum(),
+ 'post_meta' => reset( $post_meta_checksum ),
+ 'comment_meta' => reset( $comment_meta_checksum ),
);
}
@@ -638,51 +650,51 @@ class Jetpack_Sync_WP_Replicastore implements iJetpack_Sync_Replicastore {
$wpdb->queries = array();
- switch( $object_type ) {
- case "posts":
+ switch ( $object_type ) {
+ case 'posts':
$object_count = $this->post_count( null, $start_id, $end_id );
$object_table = $wpdb->posts;
$id_field = 'ID';
$where_sql = Jetpack_Sync_Settings::get_blacklisted_post_types_sql();
if ( empty( $columns ) ) {
- $columns = Jetpack_Sync_Defaults::$default_post_checksum_columns;
+ $columns = Jetpack_Sync_Defaults::$default_post_checksum_columns;
}
break;
- case "post_meta":
+ case 'post_meta':
$object_table = $wpdb->postmeta;
$where_sql = Jetpack_Sync_Settings::get_whitelisted_post_meta_sql();
$object_count = $this->meta_count( $object_table, $where_sql, $start_id, $end_id );
$id_field = 'meta_id';
if ( empty( $columns ) ) {
- $columns = Jetpack_Sync_Defaults::$default_post_meta_checksum_columns;
+ $columns = Jetpack_Sync_Defaults::$default_post_meta_checksum_columns;
}
break;
- case "comments":
+ case 'comments':
$object_count = $this->comment_count( null, $start_id, $end_id );
$object_table = $wpdb->comments;
$id_field = 'comment_ID';
$where_sql = Jetpack_Sync_Settings::get_comments_filter_sql();
if ( empty( $columns ) ) {
- $columns = Jetpack_Sync_Defaults::$default_comment_checksum_columns;
+ $columns = Jetpack_Sync_Defaults::$default_comment_checksum_columns;
}
break;
- case "comment_meta":
+ case 'comment_meta':
$object_table = $wpdb->commentmeta;
$where_sql = Jetpack_Sync_Settings::get_whitelisted_comment_meta_sql();
$object_count = $this->meta_count( $object_table, $where_sql, $start_id, $end_id );
$id_field = 'meta_id';
if ( empty( $columns ) ) {
- $columns = Jetpack_Sync_Defaults::$default_post_meta_checksum_columns;
+ $columns = Jetpack_Sync_Defaults::$default_post_meta_checksum_columns;
}
break;
default:
return false;
}
- $bucket_size = intval( ceil( $object_count / $buckets ) );
+ $bucket_size = intval( ceil( $object_count / $buckets ) );
$previous_max_id = 0;
- $histogram = array();
+ $histogram = array();
$where = '1=1';
@@ -725,7 +737,7 @@ class Jetpack_Sync_WP_Replicastore implements iJetpack_Sync_Replicastore {
global $wpdb;
// sanitize to just valid MySQL column names
- $sanitized_columns = preg_grep ( '/^[0-9,a-z,A-Z$_]+$/i', $columns );
+ $sanitized_columns = preg_grep( '/^[0-9,a-z,A-Z$_]+$/i', $columns );
if ( $strip_non_ascii ) {
$columns_sql = implode( ',', array_map( array( $this, 'strip_non_ascii_sql' ), $sanitized_columns ) );
@@ -734,16 +746,16 @@ class Jetpack_Sync_WP_Replicastore implements iJetpack_Sync_Replicastore {
}
if ( $min_id !== null ) {
- $min_id = intval( $min_id );
+ $min_id = intval( $min_id );
$where_sql .= " AND $id_column >= $min_id";
}
if ( $max_id !== null ) {
- $max_id = intval( $max_id );
+ $max_id = intval( $max_id );
$where_sql .= " AND $id_column <= $max_id";
}
- $query = <<<ENDSQL
+ $query = <<<ENDSQL
SELECT CONV(BIT_XOR(CRC32(CONCAT({$columns_sql}))), 10, 16)
FROM $table
WHERE $where_sql
diff --git a/plugins/jetpack/sync/interface.jetpack-sync-replicastore.php b/plugins/jetpack/sync/interface.jetpack-sync-replicastore.php
index 706f230a..c22f4e51 100644
--- a/plugins/jetpack/sync/interface.jetpack-sync-replicastore.php
+++ b/plugins/jetpack/sync/interface.jetpack-sync-replicastore.php
@@ -1,6 +1,7 @@
<?php
/**
* Sync architecture prototype
+ *
* @author Dan Walmsley
* To run tests: phpunit --testsuite sync --filter New_Sync
*/