|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Automattic\Jetpack\Sync\Modules; |
|
4
|
|
|
|
|
5
|
|
|
class Network_Options extends \Jetpack_Sync_Module { |
|
6
|
|
|
private $network_options_whitelist; |
|
7
|
|
|
|
|
8
|
|
|
public function name() { |
|
9
|
|
|
return 'network_options'; |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
public function init_listeners( $callable ) { |
|
13
|
|
|
if ( ! is_multisite() ) { |
|
14
|
|
|
return; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
// multi site network options |
|
18
|
|
|
add_action( 'add_site_option', $callable, 10, 2 ); |
|
19
|
|
|
add_action( 'update_site_option', $callable, 10, 3 ); |
|
20
|
|
|
add_action( 'delete_site_option', $callable, 10, 1 ); |
|
21
|
|
|
|
|
22
|
|
|
$whitelist_network_option_handler = array( $this, 'whitelist_network_options' ); |
|
23
|
|
|
add_filter( 'jetpack_sync_before_enqueue_delete_site_option', $whitelist_network_option_handler ); |
|
24
|
|
|
add_filter( 'jetpack_sync_before_enqueue_add_site_option', $whitelist_network_option_handler ); |
|
25
|
|
|
add_filter( 'jetpack_sync_before_enqueue_update_site_option', $whitelist_network_option_handler ); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function init_full_sync_listeners( $callable ) { |
|
29
|
|
|
add_action( 'jetpack_full_sync_network_options', $callable ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function init_before_send() { |
|
33
|
|
|
if ( ! is_multisite() ) { |
|
34
|
|
|
return; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
// full sync |
|
38
|
|
|
add_filter( |
|
39
|
|
|
'jetpack_sync_before_send_jetpack_full_sync_network_options', |
|
40
|
|
|
array( |
|
41
|
|
|
$this, |
|
42
|
|
|
'expand_network_options', |
|
43
|
|
|
) |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function set_defaults() { |
|
48
|
|
|
$this->network_options_whitelist = \Jetpack_Sync_Defaults::$default_network_options_whitelist; |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) { |
|
52
|
|
|
if ( ! is_multisite() ) { |
|
53
|
|
|
return array( null, true ); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Tells the client to sync all options to the server |
|
58
|
|
|
* |
|
59
|
|
|
* @since 4.2.0 |
|
60
|
|
|
* |
|
61
|
|
|
* @param boolean Whether to expand options (should always be true) |
|
62
|
|
|
*/ |
|
63
|
|
|
do_action( 'jetpack_full_sync_network_options', true ); |
|
64
|
|
|
|
|
65
|
|
|
// The number of actions enqueued, and next module state (true == done) |
|
66
|
|
|
return array( 1, true ); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
function estimate_full_sync_actions( $config ) { |
|
70
|
|
|
if ( ! is_multisite() ) { |
|
71
|
|
|
return null; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return 1; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
function get_full_sync_actions() { |
|
78
|
|
|
return array( 'jetpack_full_sync_network_options' ); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
function get_all_network_options() { |
|
82
|
|
|
$options = array(); |
|
83
|
|
|
foreach ( $this->network_options_whitelist as $option ) { |
|
84
|
|
|
$options[ $option ] = get_site_option( $option ); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $options; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
function set_network_options_whitelist( $options ) { |
|
91
|
|
|
$this->network_options_whitelist = $options; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
function get_network_options_whitelist() { |
|
95
|
|
|
return $this->network_options_whitelist; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
// reject non-whitelisted network options |
|
99
|
|
|
function whitelist_network_options( $args ) { |
|
100
|
|
|
if ( ! $this->is_whitelisted_network_option( $args[0] ) ) { |
|
101
|
|
|
return false; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return $args; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
function is_whitelisted_network_option( $option ) { |
|
108
|
|
|
return is_multisite() && in_array( $option, $this->network_options_whitelist ); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function expand_network_options( $args ) { |
|
112
|
|
|
if ( $args[0] ) { |
|
113
|
|
|
return $this->get_all_network_options(); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return $args; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.