1 | <?php |
||
3 | class Jetpack_Sync_Module_Options extends Jetpack_Sync_Module { |
||
4 | private $options_whitelist; |
||
5 | |||
6 | public function name() { |
||
7 | return 'options'; |
||
8 | } |
||
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 | // full sync |
||
22 | add_action( 'jetpack_full_sync_options', $callable ); |
||
23 | |||
24 | $whitelist_option_handler = array( $this, 'whitelist_options' ); |
||
25 | add_filter( 'jetpack_sync_before_enqueue_deleted_option', $whitelist_option_handler ); |
||
26 | add_filter( 'jetpack_sync_before_enqueue_added_option', $whitelist_option_handler ); |
||
27 | add_filter( 'jetpack_sync_before_enqueue_updated_option', $whitelist_option_handler ); |
||
28 | } |
||
29 | |||
30 | public function init_before_send() { |
||
34 | |||
35 | public function set_defaults() { |
||
36 | $this->update_options_whitelist(); |
||
37 | // theme mod varies from theme to theme. |
||
38 | $this->options_whitelist[] = 'theme_mods_' . get_option( 'stylesheet' ); |
||
39 | } |
||
40 | |||
41 | function enqueue_full_sync_actions() { |
||
52 | |||
53 | function get_full_sync_actions() { |
||
56 | |||
57 | // Is public so that we don't have to store so much data all the options twice. |
||
58 | function get_all_options() { |
||
59 | $options = array(); |
||
60 | foreach ( $this->options_whitelist as $option ) { |
||
61 | $options[ $option ] = get_option( $option ); |
||
62 | } |
||
63 | |||
64 | return $options; |
||
65 | } |
||
66 | |||
67 | function update_options_whitelist() { |
||
68 | /** This filter is already documented in json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php */ |
||
69 | $this->options_whitelist = apply_filters( 'jetpack_options_whitelist', Jetpack_Sync_Defaults::$default_options_whitelist ); |
||
|
|||
70 | } |
||
71 | |||
72 | function set_options_whitelist( $options ) { |
||
73 | $this->options_whitelist = $options; |
||
74 | } |
||
75 | |||
76 | function get_options_whitelist() { |
||
77 | return $this->options_whitelist; |
||
78 | } |
||
79 | |||
80 | // reject non-whitelisted options |
||
81 | function whitelist_options( $args ) { |
||
82 | if ( ! $this->is_whitelisted_option( $args[0] ) ) { |
||
83 | return false; |
||
84 | } |
||
85 | |||
86 | return $args; |
||
87 | } |
||
88 | |||
89 | function is_whitelisted_option( $option ) { |
||
90 | return in_array( $option, $this->options_whitelist ); |
||
91 | } |
||
92 | |||
93 | function jetpack_sync_core_icon() { |
||
94 | if ( function_exists( 'get_site_icon_url' ) ) { |
||
95 | $url = get_site_icon_url(); |
||
96 | } else { |
||
97 | return; |
||
98 | } |
||
99 | |||
100 | require_once( JETPACK__PLUGIN_DIR . 'modules/site-icon/site-icon-functions.php' ); |
||
101 | // If there's a core icon, maybe update the option. If not, fall back to Jetpack's. |
||
102 | if ( ! empty( $url ) && $url !== jetpack_site_icon_url() ) { |
||
103 | // This is the option that is synced with dotcom |
||
104 | Jetpack_Options::update_option( 'site_icon_url', $url ); |
||
105 | } else if ( empty( $url ) ) { |
||
106 | Jetpack_Options::delete_option( 'site_icon_url' ); |
||
107 | } |
||
108 | } |
||
109 | |||
110 | public function expand_options( $args ) { |
||
117 | } |
||
118 |
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.