Skip to content

Commit

Permalink
Sync: ensure we run the initial sync on new connections (#14384)
Browse files Browse the repository at this point in the history
In #14204, we changed the way we initialize the Sync package,
which was a bit too strict and didn't allow for initial syncs
to happen.

Let's make sure we always hook to `jetpack_user_authorized` and
attempt to `do_initial_sync` during connections or reconnections.

There are safeguards in `do_initial_sync` to protect sites that
should sync from doing an initial sync.
  • Loading branch information
roccotripaldi authored and dereksmart committed Jan 20, 2020
1 parent 4e93353 commit 1c9772f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/sync/src/class-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ class Main {
* @action plugins_loaded
*/
public static function configure() {
// Exit out early if Sync isn't allowed.
if ( ! Actions::sync_allowed() ) {
return;
if ( Actions::sync_allowed() ) {
add_action( 'plugins_loaded', array( __CLASS__, 'on_plugins_loaded_early' ), 5 );
add_action( 'plugins_loaded', array( __CLASS__, 'on_plugins_loaded_late' ), 90 );
}

add_action( 'plugins_loaded', array( __CLASS__, 'on_plugins_loaded_early' ), 5 );
add_action( 'plugins_loaded', array( __CLASS__, 'on_plugins_loaded_late' ), 90 );
// Any hooks below are special cases that need to be declared even if Sync is not allowed.
add_action( 'jetpack_user_authorized', array( 'Automattic\\Jetpack\\Sync\\Actions', 'do_initial_sync' ), 10, 0 );
}

/**
Expand All @@ -47,7 +46,6 @@ public static function on_plugins_loaded_early() {

// We need to define this here so that it's hooked before `updating_jetpack_version` is called.
add_action( 'updating_jetpack_version', array( 'Automattic\\Jetpack\\Sync\\Actions', 'cleanup_on_upgrade' ), 10, 2 );
add_action( 'jetpack_user_authorized', array( 'Automattic\\Jetpack\\Sync\\Actions', 'do_initial_sync' ), 10, 0 );
}

/**
Expand Down

0 comments on commit 1c9772f

Please sign in to comment.