1 | <?php |
||
3 | class Jetpack_Sync_Module_Options extends Jetpack_Sync_Module { |
||
4 | private $options_whitelist; |
||
5 | |||
6 | public function name() { |
||
9 | |||
10 | public function init_listeners( $callable ) { |
||
11 | // options |
||
12 | add_action( 'added_option', $callable, 10, 2 ); |
||
13 | add_action( 'updated_option', $callable, 10, 3 ); |
||
14 | add_action( 'deleted_option', $callable, 10, 1 ); |
||
15 | |||
16 | // Sync Core Icon: Detect changes in Core's Site Icon and make it syncable. |
||
17 | add_action( 'add_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); |
||
18 | add_action( 'update_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); |
||
19 | add_action( 'delete_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); |
||
20 | |||
21 | $whitelist_option_handler = array( $this, 'whitelist_options' ); |
||
22 | add_filter( 'jetpack_sync_before_enqueue_deleted_option', $whitelist_option_handler ); |
||
23 | add_filter( 'jetpack_sync_before_enqueue_added_option', $whitelist_option_handler ); |
||
24 | add_filter( 'jetpack_sync_before_enqueue_updated_option', $whitelist_option_handler ); |
||
25 | } |
||
26 | |||
27 | public function init_full_sync_listeners( $callable ) { |
||
30 | |||
31 | public function init_before_send() { |
||
35 | |||
36 | public function set_defaults() { |
||
39 | |||
40 | function enqueue_full_sync_actions( $config ) { |
||
41 | /** |
||
42 | * Tells the client to sync all options to the server |
||
43 | * |
||
44 | * @since 4.2.0 |
||
45 | * |
||
46 | * @param boolean Whether to expand options (should always be true) |
||
47 | */ |
||
48 | do_action( 'jetpack_full_sync_options', true ); |
||
49 | |||
50 | return 1; // The number of actions enqueued |
||
51 | } |
||
52 | |||
53 | public function estimate_full_sync_actions( $config ) { |
||
56 | |||
57 | function get_full_sync_actions() { |
||
60 | |||
61 | // Is public so that we don't have to store so much data all the options twice. |
||
62 | function get_all_options() { |
||
63 | $options = array(); |
||
64 | foreach ( $this->options_whitelist as $option ) { |
||
65 | $options[ $option ] = get_option( $option ); |
||
66 | } |
||
67 | |||
68 | // add theme mods |
||
69 | $theme_mods_option = 'theme_mods_'.get_option( 'stylesheet' ); |
||
70 | $theme_mods_value = get_option( $theme_mods_option ); |
||
71 | $this->filter_theme_mods( $theme_mods_value ); |
||
72 | $options[ $theme_mods_option ] = $theme_mods_value; |
||
73 | |||
74 | return $options; |
||
75 | } |
||
76 | |||
77 | function update_options_whitelist() { |
||
81 | |||
82 | function set_options_whitelist( $options ) { |
||
85 | |||
86 | function get_options_whitelist() { |
||
89 | |||
90 | // reject non-whitelisted options |
||
91 | function whitelist_options( $args ) { |
||
92 | if ( ! $this->is_whitelisted_option( $args[0] ) ) { |
||
93 | return false; |
||
94 | } |
||
95 | |||
96 | // filter our weird array( false ) value for theme_mods_* |
||
97 | if ( 'theme_mods_' === substr( $args[0], 0, 11 ) ) { |
||
98 | $this->filter_theme_mods( $args[1] ); |
||
99 | if ( isset( $args[2] ) ) { |
||
100 | $this->filter_theme_mods( $args[2] ); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | return $args; |
||
105 | } |
||
106 | |||
107 | function is_whitelisted_option( $option ) { |
||
108 | return in_array( $option, $this->options_whitelist ) || 'theme_mods_' === substr( $option, 0, 11 ); |
||
109 | } |
||
110 | |||
111 | private function filter_theme_mods( &$value ) { |
||
112 | if ( is_array( $value ) && isset( $value[0] ) ) { |
||
113 | unset( $value[0] ); |
||
114 | } |
||
115 | } |
||
116 | |||
117 | function jetpack_sync_core_icon() { |
||
133 | |||
134 | public function expand_options( $args ) { |
||
141 | } |
||
142 |
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.