PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.3
Jetpack – WP Security, Backup, Speed, & Growth v6.3
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / sync / class.jetpack-sync-module-network-options.php

class.jetpack-sync-module-network-options.php in Jetpack – WP Security, Backup, Speed, & Growth 6.3, at sync/class.jetpack-sync-module-network-options.php

114 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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;
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