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( $this, 'filter_update_keys' ), 10, 2 ); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function init_before_send() { |
20
|
|
|
// full sync |
21
|
|
|
add_filter( 'jetpack_sync_before_send_jetpack_full_sync_updates', array( $this, 'expand_updates' ) ); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function enqueue_full_sync_actions() { |
25
|
|
|
/** |
26
|
|
|
* Tells the client to sync all updates to the server |
27
|
|
|
* |
28
|
|
|
* @since 4.2.0 |
29
|
|
|
* |
30
|
|
|
* @param boolean Whether to expand updates (should always be true) |
31
|
|
|
*/ |
32
|
|
|
do_action( 'jetpack_full_sync_updates', true ); |
33
|
|
|
return 1; // The number of actions enqueued |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function get_full_sync_actions() { |
37
|
|
|
return array( 'jetpack_full_sync_updates' ); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function get_all_updates() { |
41
|
|
|
return array( |
42
|
|
|
'core' => get_site_transient( 'update_core' ), |
43
|
|
|
'plugins' => get_site_transient( 'update_plugins' ), |
44
|
|
|
'themes' => get_site_transient( 'update_themes' ), |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// removes unnecessary keys from synced updates data |
49
|
|
|
function filter_update_keys( $args ) { |
50
|
|
|
$updates = $args[0]; |
51
|
|
|
|
52
|
|
|
if ( isset( $updates->no_update ) ) { |
53
|
|
|
unset( $updates->no_update ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $args; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function expand_updates( $args ) { |
60
|
|
|
if ( $args[0] ) { |
61
|
|
|
return $this->get_all_updates(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $args; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|