Completed
Push — instant-search-master ( 95535d...2c1eb1 )
by
unknown
22:37 queued 16:04
created

Main::configure()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This class hooks the main sync actions.
4
 *
5
 * @package automattic/jetpack-sync
6
 */
7
8
namespace Automattic\Jetpack\Sync;
9
10
use Automattic\Jetpack\Sync\Actions as Sync_Actions;
11
12
/**
13
 * Jetpack Sync main class.
14
 */
15
class Main {
16
17
	/**
18
	 * Sets up event handlers for the Sync package. Is used from the Config package.
19
	 *
20
	 * @action plugins_loaded
21
	 */
22
	public static function configure() {
23
		if ( Actions::sync_allowed() ) {
24
			add_action( 'plugins_loaded', array( __CLASS__, 'on_plugins_loaded_early' ), 5 );
25
			add_action( 'plugins_loaded', array( __CLASS__, 'on_plugins_loaded_late' ), 90 );
26
		}
27
		// Any hooks below are special cases that need to be declared even if Sync is not allowed.
28
		add_action( 'jetpack_user_authorized', array( 'Automattic\\Jetpack\\Sync\\Actions', 'do_initial_sync' ), 10, 0 );
29
	}
30
31
	/**
32
	 * Initialize the main sync actions.
33
	 *
34
	 * @action plugins_loaded
35
	 */
36
	public static function on_plugins_loaded_early() {
37
		/**
38
		 * Additional Sync modules can be carried out into their own packages and they
39
		 * will get their own config settings.
40
		 *
41
		 * For now additional modules are enabled based on whether the third party plugin
42
		 * class exists or not.
43
		 */
44
		Sync_Actions::initialize_woocommerce();
45
		Sync_Actions::initialize_wp_super_cache();
46
47
		// We need to define this here so that it's hooked before `updating_jetpack_version` is called.
48
		add_action( 'updating_jetpack_version', array( 'Automattic\\Jetpack\\Sync\\Actions', 'cleanup_on_upgrade' ), 10, 2 );
49
	}
50
51
	/**
52
	 * Runs after most of plugins_loaded hook functions have been run.
53
	 *
54
	 * @action plugins_loaded
55
	 */
56
	public static function on_plugins_loaded_late() {
57
		/*
58
		 * Init after plugins loaded and before the `init` action. This helps with issues where plugins init
59
		 * with a high priority or sites that use alternate cron.
60
		 */
61
		Sync_Actions::init();
62
	}
63
64
65
}
66