Completed
Push — fix/videopress-missing-from-se... ( 60564b )
by
unknown
22:41 queued 12:31
created

sync/class.jetpack-sync-module-network-options.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
class Jetpack_Sync_Module_Network_Options extends Jetpack_Sync_Module {
4
	private $network_options_whitelist;
5
6
	public function name() {
7
		return 'network_options';
8
	}
9
10
	public function init_listeners( $callable ) {
11
		if ( ! is_multisite() ) {
12
			return;
13
		}
14
15
		// multi site network options
16
		add_action( 'add_site_option', $callable, 10, 2 );
17
		add_action( 'update_site_option', $callable, 10, 3 );
18
		add_action( 'delete_site_option', $callable, 10, 1 );
19
20
		$whitelist_network_option_handler = array( $this, 'whitelist_network_options' );
21
		add_filter( 'jetpack_sync_before_enqueue_delete_site_option', $whitelist_network_option_handler );
22
		add_filter( 'jetpack_sync_before_enqueue_add_site_option', $whitelist_network_option_handler );
23
		add_filter( 'jetpack_sync_before_enqueue_update_site_option', $whitelist_network_option_handler );
24
	}
25
26
	public function init_full_sync_listeners( $callable ) {
27
		add_action( 'jetpack_full_sync_network_options', $callable );
28
	}
29
30
	public function init_before_send() {
31
		if ( ! is_multisite() ) {
32
			return;
33
		}
34
35
		// full sync
36
		add_filter( 'jetpack_sync_before_send_jetpack_full_sync_network_options', array(
37
			$this,
38
			'expand_network_options',
39
		) );
40
	}
41
42
	public function set_defaults() {
43
		$this->network_options_whitelist = Jetpack_Sync_Defaults::$default_network_options_whitelist;
0 ignored issues
show
The property default_network_options_whitelist cannot be accessed from this context as it is declared private in class Jetpack_Sync_Defaults.

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.

Loading history...
44
	}
45
46
	function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) {
47
		if ( ! is_multisite() ) {
48
			return array( 0, true );
49
		}
50
51
		/**
52
		 * Tells the client to sync all options to the server
53
		 *
54
		 * @since 4.2.0
55
		 *
56
		 * @param boolean Whether to expand options (should always be true)
57
		 */
58
		do_action( 'jetpack_full_sync_network_options', true );
59
60
		// The number of actions enqueued, and next module state (true == done)
61
		return array( 1, true );
62
	}
63
64
	function estimate_full_sync_actions( $config ) {
65
		if ( ! is_multisite() ) {
66
			return 0;
67
		}
68
		
69
		return 1;
70
	}
71
72
	function get_full_sync_actions() {
73
		return array( 'jetpack_full_sync_network_options' );
74
	}
75
76
	function get_all_network_options() {
77
		$options = array();
78
		foreach ( $this->network_options_whitelist as $option ) {
79
			$options[ $option ] = get_site_option( $option );
80
		}
81
82
		return $options;
83
	}
84
85
	function set_network_options_whitelist( $options ) {
86
		$this->network_options_whitelist = $options;
87
	}
88
89
	function get_network_options_whitelist() {
90
		return $this->network_options_whitelist;
91
	}
92
93
	// reject non-whitelisted network options
94
	function whitelist_network_options( $args ) {
95
		if ( ! $this->is_whitelisted_network_option( $args[0] ) ) {
96
			return false;
97
		}
98
99
		return $args;
100
	}
101
102
	function is_whitelisted_network_option( $option ) {
103
		return is_multisite() && in_array( $option, $this->network_options_whitelist );
104
	}
105
106
	public function expand_network_options( $args ) {
107
		if ( $args[0] ) {
108
			return $this->get_all_network_options();
109
		}
110
111
		return $args;
112
	}
113
}
114