1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module { |
4
|
|
|
function name() { |
5
|
|
|
return 'updates'; |
6
|
|
|
} |
7
|
|
|
|
8
|
|
|
public function init_listeners( $callable ) { |
9
|
|
|
add_action( 'set_site_transient_update_plugins', $callable, 10, 1 ); |
10
|
|
|
add_action( 'set_site_transient_update_themes', $callable, 10, 1 ); |
11
|
|
|
add_action( 'set_site_transient_update_core', $callable, 10, 1 ); |
12
|
|
|
|
13
|
|
|
// full sync |
14
|
|
|
add_action( 'jetpack_full_sync_updates', $callable ); |
15
|
|
|
|
16
|
|
|
add_filter( 'jetpack_sync_before_enqueue_set_site_transient_update_plugins', array( |
17
|
|
|
$this, |
18
|
|
|
'filter_update_keys', |
19
|
|
|
), 10, 2 ); |
20
|
|
|
add_filter( 'jetpack_sync_before_enqueue_upgrader_process_complete', array( |
21
|
|
|
$this, |
22
|
|
|
'filter_upgrader_process_complete', |
23
|
|
|
), 10, 2 ); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function init_before_send() { |
27
|
|
|
// full sync |
28
|
|
|
add_filter( 'jetpack_sync_before_send_jetpack_full_sync_updates', array( $this, 'expand_updates' ) ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function enqueue_full_sync_actions() { |
32
|
|
|
/** |
33
|
|
|
* Tells the client to sync all updates to the server |
34
|
|
|
* |
35
|
|
|
* @since 4.2.0 |
36
|
|
|
* |
37
|
|
|
* @param boolean Whether to expand updates (should always be true) |
38
|
|
|
*/ |
39
|
|
|
do_action( 'jetpack_full_sync_updates', true ); |
40
|
|
|
|
41
|
|
|
return 1; // The number of actions enqueued |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function get_full_sync_actions() { |
45
|
|
|
return array( 'jetpack_full_sync_updates' ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function get_all_updates() { |
49
|
|
|
return array( |
50
|
|
|
'core' => get_site_transient( 'update_core' ), |
51
|
|
|
'plugins' => get_site_transient( 'update_plugins' ), |
52
|
|
|
'themes' => get_site_transient( 'update_themes' ), |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// removes unnecessary keys from synced updates data |
57
|
|
|
function filter_update_keys( $args ) { |
58
|
|
|
$updates = $args[0]; |
59
|
|
|
|
60
|
|
|
if ( isset( $updates->no_update ) ) { |
61
|
|
|
unset( $updates->no_update ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $args; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
function filter_upgrader_process_complete( $args ) { |
68
|
|
|
array_shift( $args ); |
69
|
|
|
|
70
|
|
|
return $args; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function expand_updates( $args ) { |
74
|
|
|
if ( $args[0] ) { |
75
|
|
|
return $this->get_all_updates(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $args; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|