1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Jetpack_Sync_Actions { |
4
|
|
|
static $client = null; |
|
|
|
|
5
|
|
|
|
6
|
|
|
static function init() { |
7
|
|
|
/** |
8
|
|
|
* Fires on every request before default loading sync code. |
9
|
|
|
* Return false to not load sync code and hook sync actions. |
10
|
|
|
* |
11
|
|
|
* @since 4.2.0 |
12
|
|
|
* |
13
|
|
|
* @param bool should we load sync code for this request |
14
|
|
|
*/ |
15
|
|
|
if ( ! apply_filters( 'jetpack_sync_should_load', |
16
|
|
|
( |
17
|
|
|
$_SERVER['REQUEST_METHOD'] === 'POST' |
18
|
|
|
|| |
19
|
|
|
current_user_can( 'manage_options' ) |
20
|
|
|
|| |
21
|
|
|
is_admin() |
22
|
|
|
|| |
23
|
|
|
defined( 'PHPUNIT_JETPACK_TESTSUITE' ) |
24
|
|
|
) |
25
|
|
|
&& |
26
|
|
|
!( Jetpack::is_development_mode() || Jetpack::is_staging_site() ) |
27
|
|
|
|
28
|
|
|
) ) { |
29
|
|
|
return; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
require_once dirname( __FILE__ ) . '/class.jetpack-sync-client.php'; |
33
|
|
|
|
34
|
|
|
self::$client = Jetpack_Sync_Client::getInstance(); |
35
|
|
|
|
36
|
|
|
// bind the do_sync process to shutdown |
37
|
|
|
add_action( 'shutdown', array( self::$client, 'do_sync' ) ); |
38
|
|
|
|
39
|
|
|
// bind the sending process |
40
|
|
|
add_filter( 'jetpack_sync_client_send_data', array( __CLASS__, 'send_data' ) ); |
41
|
|
|
|
42
|
|
|
// On jetpack registration |
43
|
|
|
add_action( 'jetpack_site_registered', array( __CLASS__, 'schedule_full_sync' ) ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
static function send_data( $data ) { |
47
|
|
|
Jetpack::load_xml_rpc_client(); |
48
|
|
|
|
49
|
|
|
// add an extra parameter to the URL so we can tell it's a sync action |
50
|
|
|
$url = add_query_arg( 'sync', '1', Jetpack::xmlrpc_api_url() ); |
51
|
|
|
|
52
|
|
|
$rpc = new Jetpack_IXR_Client( array( |
53
|
|
|
'url' => $url, |
54
|
|
|
'user_id' => get_current_user_id(), |
55
|
|
|
'timeout' => 30 |
56
|
|
|
) ); |
57
|
|
|
|
58
|
|
|
$result = $rpc->query( 'jetpack.syncActions', $data ); |
59
|
|
|
|
60
|
|
|
if ( ! $result ) { |
61
|
|
|
return $rpc->get_jetpack_error(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $rpc->getResponse(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
static function schedule_full_sync() { |
68
|
|
|
wp_schedule_single_event( time() + 1, 'jetpack_sync_full' ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
} |
72
|
|
|
// Allow other plugins to add filters before we initalize the actions. |
73
|
|
|
add_action( 'init', array( 'Jetpack_Sync_Actions', 'init' ), 11, 0 ); |
74
|
|
|
|
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.