Completed
Push — add/sso-analytics ( 683a91...e67d7d )
by
unknown
162:06 queued 152:34
created

Jetpack_Sync_Actions   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3
Metric Value
dl 0
loc 36
rs 10
wmc 4
lcom 2
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 13 1
A send_data() 0 13 2
A schedule_full_sync() 0 3 1
1
<?php
2
3
require_once 'class.jetpack-sync-client.php';
4
5
class Jetpack_Sync_Actions {
6
	static $client = null;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $client.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
7
8
	static function init() {
9
10
		self::$client = Jetpack_Sync_Client::getInstance();
11
12
		// bind the do_sync process to shutdown
13
		add_action( 'shutdown', array( self::$client, 'do_sync' ) );
14
15
		// bind the sending process
16
		add_filter( 'jetpack_sync_client_send_data', array( __CLASS__, 'send_data' ) );
17
18
		// On jetpack registration
19
		add_action( 'jetpack_site_registered', array( __CLASS__, 'schedule_full_sync' ) );
20
	}
21
22
	static function send_data( $data ) {
23
		Jetpack::load_xml_rpc_client();
24
		$rpc    = new Jetpack_IXR_Client( array(
25
			'user_id' => get_current_user_id(),
26
			'timeout' => 30
27
		) );
28
		$result = $rpc->query( 'jetpack.syncActions', $data );
29
		if ( ! $result ) {
30
			return $rpc->get_jetpack_error();
31
		}
32
33
		return $rpc->getResponse();
34
	}
35
36
	static function schedule_full_sync() {
37
		wp_schedule_single_event( strftime( '+1 second' ), 'jetpack_sync_full' );
38
	}
39
40
}
41
42
Jetpack_Sync_Actions::init();
43