1 | <?php |
||
9 | class Jetpack_Sync_Actions { |
||
10 | static $sender = null; |
||
|
|||
11 | static $listener = null; |
||
12 | |||
13 | static function init() { |
||
14 | |||
15 | // On jetpack authorization, schedule a full sync |
||
16 | add_action( 'jetpack_client_authorized', array( __CLASS__, 'schedule_full_sync' ) ); |
||
17 | |||
18 | // Sync connected user role changes to .com |
||
19 | require_once dirname( __FILE__ ) . '/class.jetpack-sync-users.php'; |
||
20 | |||
21 | // everything below this point should only happen if we're a valid sync site |
||
22 | if ( ! self::sync_allowed() ) { |
||
23 | return; |
||
24 | } |
||
25 | |||
26 | // cron hooks |
||
27 | add_action( 'jetpack_sync_send_db_checksum', array( __CLASS__, 'send_db_checksum' ) ); |
||
28 | add_action( 'jetpack_sync_full', array( __CLASS__, 'do_full_sync' ) ); |
||
29 | add_action( 'jetpack_sync_send_pending_data', array( __CLASS__, 'do_send_pending_data' ) ); |
||
30 | |||
31 | if ( ! wp_next_scheduled ( 'jetpack_sync_send_db_checksum' ) ) { |
||
32 | // Schedule a job to send DB checksums once an hour |
||
33 | wp_schedule_event( time(), 'hourly', 'jetpack_sync_send_db_checksum' ); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Fires on every request before default loading sync listener code. |
||
38 | * Return false to not load sync listener code that monitors common |
||
39 | * WP actions to be serialized. |
||
40 | * |
||
41 | * By default this returns true for non-GET-requests, or requests where the |
||
42 | * user is logged-in. |
||
43 | * |
||
44 | * @since 4.2.0 |
||
45 | * |
||
46 | * @param bool should we load sync listener code for this request |
||
47 | */ |
||
48 | if ( apply_filters( 'jetpack_sync_listener_should_load', |
||
49 | ( |
||
50 | $_SERVER['REQUEST_METHOD'] !== 'GET' |
||
51 | || |
||
52 | is_user_logged_in() |
||
53 | || |
||
54 | defined( 'PHPUNIT_JETPACK_TESTSUITE' ) |
||
55 | ) |
||
56 | ) ) { |
||
57 | self::initialize_listener(); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Fires on every request before default loading sync sender code. |
||
62 | * Return false to not load sync sender code that serializes pending |
||
63 | * data and sends it to WPCOM for processing. |
||
64 | * |
||
65 | * By default this returns true for POST requests, admin requests, or requests |
||
66 | * by users who can manage_options. |
||
67 | * |
||
68 | * @since 4.2.0 |
||
69 | * |
||
70 | * @param bool should we load sync sender code for this request |
||
71 | */ |
||
72 | if ( apply_filters( 'jetpack_sync_sender_should_load', |
||
73 | ( |
||
74 | $_SERVER['REQUEST_METHOD'] === 'POST' |
||
75 | || |
||
76 | current_user_can( 'manage_options' ) |
||
77 | || |
||
78 | is_admin() |
||
79 | || |
||
80 | defined( 'PHPUNIT_JETPACK_TESTSUITE' ) |
||
81 | ) |
||
82 | ) ) { |
||
83 | self::initialize_sender(); |
||
84 | add_action( 'shutdown', array( self::$sender, 'do_sync' ) ); |
||
85 | } |
||
86 | |||
87 | } |
||
88 | |||
89 | static function sync_allowed() { |
||
93 | |||
94 | static function send_data( $data, $codec_name, $sent_timestamp ) { |
||
117 | |||
118 | static function schedule_full_sync() { |
||
121 | |||
122 | static function do_full_sync() { |
||
131 | |||
132 | static function do_send_pending_data() { |
||
136 | |||
137 | static function send_db_checksum() { |
||
143 | |||
144 | static function initialize_listener() { |
||
148 | |||
149 | static function initialize_sender() { |
||
156 | } |
||
157 | |||
160 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.