Completed
Push — add/sync-action ( 6ee1eb...450f6e )
by
unknown
09:06
created

Jetpack_Sync_Client::get_check_sum()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
require_once dirname( __FILE__ ) . '/class.jetpack-sync-deflate-codec.php';
3
require_once dirname( __FILE__ ) . '/class.jetpack-sync-queue.php';
4
require_once dirname( __FILE__ ) . '/class.jetpack-sync-functions.php';
5
require_once dirname( __FILE__ ) . '/class.jetpack-sync-full.php';
6
require_once dirname( __FILE__ ) . '/class.jetpack-sync-defaults.php';
7
8
class Jetpack_Sync_Client {
9
	
10
	static $constants_checksum_option_name = 'jetpack_constants_sync_checksum';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $constants_checksum_option_name.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
11
	static $functions_checksum_option_name = 'jetpack_functions_sync_checksum';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $functions_checksum_option_name.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
12
13
	private $checkout_memory_size;
14
	private $upload_limit;
15
	private $sync_queue;
16
	private $full_sync_client;
17
	private $codec;
18
	private $options_whitelist;
19
	private $constants_whitelist;
20
	private $meta_types = array( 'post', 'comment' );
21
	private $callable_whitelist;
22
	private $network_options_whitelist;
23
	private $taxonomy_whitelist;
24
25
	// singleton functions
26
	private static $instance;
27
28
	public static function getInstance() {
29
		if ( null === self::$instance ) {
30
			self::$instance = new self();
31
		}
32
33
		return self::$instance;
34
	}
35
36
	// this is necessary because you can't use "new" when you declare instance properties >:(
37
	protected function __construct() {
38
		$this->set_defaults();
39
		$this->init();
40
	}
41
42
	private function init() {
43
44
		$handler = array( $this, 'action_handler' );
45
46
		/**
47
		 * Most of the following hooks are sent to the same $handler 
48
		 * for immediate serialization and queuing be sent to the server.
49
		 * The only exceptions are actions which need additional processing.
50
		 */
51
52
		// constants
53
		add_action( 'jetpack_sync_current_constants', $handler, 10 );
54
55
		// functions
56
		add_action( 'jetpack_sync_current_callables', $handler, 10 );
57
58
		// posts
59
		add_action( 'wp_insert_post', $handler, 10, 3 );
60
		add_action( 'deleted_post', $handler, 10 );
61
		add_filter( 'jetpack_sync_before_send_wp_insert_post', array( $this, 'expand_wp_insert_post' ) );
62
		add_action( 'transition_post_status', $handler, 10, 3 ); // $new_status, $old_status, $post)
63
		add_filter( 'jetpack_sync_before_send_transition_post_status', array( $this, 'expand_transition_post_status' ) );
64
65
		// attachments
66
67
		add_action( 'edit_attachment', array( $this, 'send_attachment_info' ) );
68
		// Once we don't have to support 4.3 we can start using add_action( 'attachment_updated', $handler, 10, 3 ); instead
69
		add_action( 'add_attachment', array( $this, 'send_attachment_info' ) );
70
		add_action( 'jetpack_sync_save_add_attachment', $handler, 10, 2 );
71
72
		// comments
73
		add_action( 'wp_insert_comment', $handler, 10, 2 );
74
		add_action( 'deleted_comment', $handler, 10 );
75
		add_action( 'trashed_comment', $handler, 10 );
76
		add_action( 'spammed_comment', $handler, 10 );
77
78
		// even though it's messy, we implement these hooks because 
79
		// the edit_comment hook doesn't include the data
80
		// so this saves us a DB read for every comment event
81
		foreach ( array( '', 'trackback', 'pingback' ) as $comment_type ) {
82
			foreach ( array( 'unapproved', 'approved' ) as $comment_status ) {
83
				add_action( "comment_{$comment_status}_{$comment_type}", $handler, 10, 2 );
84
			}
85
		}
86
87
		// options
88
		add_action( 'added_option', $handler, 10, 2 );
89
		add_action( 'updated_option', $handler, 10, 3 );
90
		add_action( 'deleted_option', $handler, 10, 1 );
91
92
		// Sync Core Icon: Detect changes in Core's Site Icon and make it syncable.
93
		add_action( 'add_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) );
94
		add_action( 'update_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) );
95
		add_action( 'delete_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) );
96
97
		// wordpress version
98
		add_action( 'upgrader_process_complete', array( $this, 'send_wp_version' ), 10, 2 );
99
		add_action( 'jetpack_sync_wp_version', $handler );
100
101
		// themes
102
		add_action( 'switch_theme', array( $this, 'send_theme_info' ) );
103
		add_action( 'jetpack_sync_current_theme_support', $handler, 10 ); // custom hook, see meta-hooks below
104
105
		// post-meta, and in the future - other meta?
106
		foreach ( $this->meta_types as $meta_type ) {
107
			add_action( "added_{$meta_type}_meta", $handler, 10, 4 );
108
			add_action( "updated_{$meta_type}_meta", $handler, 10, 4 );
109
			add_action( "deleted_{$meta_type}_meta", $handler, 10, 4 );
110
		}
111
112
		// terms
113
		add_action( 'created_term', array( $this, 'save_term_handler' ), 10, 3 );
114
		add_action( 'edited_term', array( $this, 'save_term_handler' ), 10, 3 );
115
		add_action( 'jetpack_sync_save_term', $handler, 10, 4 );
116
		add_action( 'delete_term', $handler, 10, 4 );
117
		add_action( 'set_object_terms', $handler, 10, 5 );
118
		add_action( 'deleted_term_relationships', $handler, 10 , 2 );
119
120
		// users
121
		add_action( 'user_register', array( $this, 'save_user_handler' ) );
122
		add_action( 'profile_update', array( $this, 'save_user_handler' ), 10, 2 );
123
		add_action( 'jetpack_sync_save_user', $handler, 10, 2 );
124
		add_action( 'deleted_user', $handler, 10, 2 );
125
126
		// user roles
127
		add_action( 'add_user_role', array( $this,'save_user_role_handler' ), 10, 2 );
128
		add_action( 'set_user_role', array( $this,'save_user_role_handler' ), 10, 3 );
129
		add_action( 'remove_user_role', array( $this,'save_user_role_handler' ), 10, 2 );
130
131
132
		// user capabilities
133
		add_action( 'added_user_meta', array( $this, 'save_user_cap_handler' ), 10, 4 );
134
		add_action( 'updated_user_meta', array( $this, 'save_user_cap_handler' ), 10, 4 );
135
		add_action( 'deleted_user_meta', array( $this, 'save_user_cap_handler' ), 10, 4 );
136
137
		// themes
138
		add_action( 'set_site_transient_update_plugins', $handler, 10, 1 );
139
		add_action( 'set_site_transient_update_themes', $handler, 10, 1 );
140
		add_action( 'set_site_transient_update_core', $handler, 10, 1 );
141
142
		// multi site network options
143
		if ( $this->is_multisite ) {
0 ignored issues
show
Bug introduced by
The property is_multisite does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
144
			add_action( 'add_site_option', $handler, 10, 2 );
145
			add_action( 'update_site_option', $handler, 10, 3 );
146
			add_action( 'delete_site_option', $handler, 10, 1 );
147
		}
148
149
		// synthetic actions for full sync
150
		add_action( 'jetpack_full_sync_start', $handler );
151
		add_action( 'jetpack_full_sync_end', $handler );
152
		add_action( 'jetpack_full_sync_options', $handler );
153
		add_action( 'jetpack_full_sync_posts', $handler ); // also sends post meta
154
		add_action( 'jetpack_full_sync_comments', $handler ); // also send comments meta
155
		add_action( 'jetpack_full_sync_users', $handler );
156
		add_action( 'jetpack_full_sync_terms', $handler, 10, 2 );
157
		if ( is_multisite() ) {
158
			add_action( 'jetpack_full_sync_network_options', $handler );
159
		}
160
161
162
		// TODO: Callables, Constanst, Network Options, Users, Terms
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
163
164
		/**
165
		 * Sync all pending actions with server
166
		 */
167
		add_action( 'jetpack_sync_actions', array( $this, 'do_sync' ) );
168
	}
169
170
	// TODO: Refactor to use one set whitelist function, with one is_whitelisted.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
171
	function set_options_whitelist( $options ) {
172
		$this->options_whitelist = $options;
173
	}
174
175
	function set_constants_whitelist( $constants ) {
176
		$this->constants_whitelist = $constants;
177
	}
178
179
	function get_callable_whitelist( $functions ) {
0 ignored issues
show
Unused Code introduced by
The parameter $functions is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
180
		return $this->callable_whitelist;
181
	}
182
183
	function set_callable_whitelist( $functions ) {
184
		$this->callable_whitelist = $functions;
185
	}
186
187
	function set_network_options_whitelist( $options ) {
188
		$this->network_options_whitelist = $options;
189
	}
190
191
	function set_send_buffer_memory_size( $size ) {
192
		$this->checkout_memory_size = $size;
193
	}
194
195
	// in bytes
196
	function set_upload_limit( $limit ) {
197
		$this->upload_limit = $limit;
198
	}
199
200
	function set_taxonomy_whitelist( $taxonomies ) {
201
		$this->taxonomy_whitelist = $taxonomies;
202
	}
203
204
	function is_whitelisted_option( $option ) {
205
		return in_array( $option, $this->options_whitelist );
206
	}
207
208
	function is_whitelisted_network_option( $option ) {
209
		return $this->is_multisite && in_array( $option, $this->network_options_whitelist );
210
	}
211
212
	function set_codec( iJetpack_Sync_Codec $codec ) {
213
		$this->codec = $codec;
214
	}
215
216
	function set_full_sync_client( $full_sync_client ) {
217
		if ( $this->full_sync_client ) {
218
			remove_action( 'jetpack_sync_full', array( $this->full_sync_client, 'start' ) );
219
		}
220
221
		$this->full_sync_client = $full_sync_client;
222
223
		/**
224
		 * Sync all objects in the database with the server
225
		 */
226
		add_action( 'jetpack_sync_full', array( $this->full_sync_client, 'start' ) );
227
	}
228
229
	function get_full_sync_client() {
230
		return $this->full_sync_client;
231
	}
232
233
	function action_handler() {
234
		// TODO: it's really silly to have this function here - it should be
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
235
		// wherever we initialize the action listeners or we're just wasting cycles
236
		if ( Jetpack::is_development_mode() || Jetpack::is_staging_site() ) {
237
			return false;
238
		}
239
240
		$current_filter = current_filter();
241
		$args           = func_get_args();
242
243
		if ( $current_filter === 'wp_insert_post' && $args[1]->post_type === 'revision' ) {
244
			return;
245
		}
246
247
		if ( in_array( $current_filter, array( 'deleted_option', 'added_option', 'updated_option' ) )
248
		     &&
249
		     ! $this->is_whitelisted_option( $args[0] )
250
		) {
251
			return;
252
		}
253
254
		if ( in_array( $current_filter, array( 'delete_site_option', 'add_site_option', 'update_site_option' ) )
255
		     &&
256
		     ! $this->is_whitelisted_network_option( $args[0] )
257
		) {
258
			return;
259
		}
260
261
		// don't sync private meta
262
		if ( preg_match( '/^(added|updated|deleted)_.*_meta$/', $current_filter )
263
		     && $args[2][0] === '_'
264
		     && ! in_array( $args[2], Jetpack_Sync_Defaults::$default_whitelist_meta_keys ) ) {
0 ignored issues
show
Bug introduced by
The property default_whitelist_meta_keys 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...
265
			return;
266
		}
267
268
		$this->sync_queue->add( array(
269
			$current_filter,
270
			$args,
271
			get_current_user_id(),
272
			microtime(true)
273
		) );
274
	}
275
276
	function send_theme_info() {
277
		global $_wp_theme_features;
278
279
		$theme_support = array();
280
281
		foreach( Jetpack_Sync_Defaults::$default_theme_support_whitelist as $theme_feature ) {
0 ignored issues
show
Bug introduced by
The property default_theme_support_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...
282
			$has_support = current_theme_supports( $theme_feature );
283
			if ( $has_support ) {
284
				$theme_support[ $theme_feature ] = $_wp_theme_features[ $theme_feature ];
285
			}
286
287
		}
288
		do_action( 'jetpack_sync_current_theme_support', $theme_support );
289
	}
290
291
	function send_wp_version( $update, $meta_data ) {
292
		if ( 'update' === $meta_data['action'] && 'core' === $meta_data['type'] ) {
293
			global $wp_version;
294
			do_action( 'jetpack_sync_wp_version', $wp_version );
295
		}
296
	}
297
298
	function save_term_handler( $term_id, $tt_id, $taxonomy ) {
299
		if ( class_exists('WP_Term') ) {
300
			$term_object = WP_Term::get_instance( $term_id, $taxonomy );
301
		} else {
302
			$term_object = get_term_by( 'id', $term_id, $taxonomy );
303
		}
304
305
		do_action( 'jetpack_sync_save_term', $term_object );
306
	}
307
308
	function send_attachment_info( $attachment_id ) {
309
		$attachment = get_post( $attachment_id );
310
		do_action( 'jetpack_sync_save_add_attachment', $attachment_id, $attachment );
311
	}
312
313
	function save_user_handler( $user_id, $old_user_data = null ) {
314
		$user = $this->sanitize_user( get_user_by( 'id', $user_id ) );
315
316
		// Older versions of WP don't pass the old_user_data in ->data
317
		if ( isset( $old_user_data->data ) ) {
318
			$old_user = $old_user_data->data;
319
		} else {
320
			$old_user = $old_user_data;
321
		}
322
323
		if ( $old_user !== null ) {
324
			unset( $old_user->user_pass );
325
			if ( serialize( $old_user ) === serialize( $user->data ) ) {
326
				return;
327
			}
328
		}
329
		do_action( 'jetpack_sync_save_user', $user );
330
	}
331
332
	function save_user_role_handler( $user_id, $role, $old_roles = null ) {
0 ignored issues
show
Unused Code introduced by
The parameter $role is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $old_roles is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
333
		$user = $this->sanitize_user( get_user_by( 'id', $user_id ) );
334
		do_action( 'jetpack_sync_save_user', $user );
335
	}
336
337
	function save_user_cap_handler( $meta_id, $user_id, $meta_key, $capabilities ) {
0 ignored issues
show
Unused Code introduced by
The parameter $capabilities is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
338
		$user = $this->sanitize_user( get_user_by( 'id', $user_id ) );
339
		if ( $meta_key === $user->cap_key ) {
340
			do_action( 'jetpack_sync_save_user', $user );
341
		}
342
	}
343
344
	public function sanitize_user( $user ) {
345
		unset( $user->data->user_pass );
346
		return $user;
347
	}
348
349
350
	function do_sync() {
351
		if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
352
			$this->schedule_sync( "+1 minute" );
353
			return false;
354
		}
355
356
		$this->maybe_sync_constants();
357
		$this->maybe_sync_callables();
358
359
		if ( $this->sync_queue->size() === 0 ) {
360
			return false;
361
		}
362
363
		$buffer = $this->sync_queue->checkout_with_memory_limit( $this->checkout_memory_size );
364
365
		if ( ! $buffer ) {
366
			// buffer has no items
367
			return;
368
		}
369
370
		if ( is_wp_error( $buffer ) ) {
371
			// another buffer is currently sending
372
			return;
373
		}
374
375
		$upload_size = 0;
376
		$items_to_send = array();
377
378
		// we estimate the total encoded size as we go by encoding each item individually
379
		// this is expensive, but the only way to really know :/
380
		foreach ( $buffer->get_items() as $item ) {
381
382
			// expand item data, e.g. IDs into posts (for full sync)
383
			$item[1] = apply_filters( "jetpack_sync_before_send_".$item[0], $item[1] );
384
385
			$upload_size += strlen( $this->codec->encode( $item ) );
386
			if ( $upload_size > $this->upload_limit && count( $items_to_send ) > 0 ) {
387
				break;
388
			}
389
390
			$items_to_send[] = $item;
391
		}
392
393
		$data = $this->codec->encode( $items_to_send );
394
395
		/**
396
		 * Fires when data is ready to send to the server.
397
		 * Return false or WP_Error to abort the sync (e.g. if there's an error)
398
		 * The items will be automatically re-sent later
399
		 *
400
		 * @since 4.1
401
		 *
402
		 * @param array $data The action buffer
403
		 */
404
		$result = apply_filters( 'jetpack_sync_client_send_data', $data );
405
406
		if ( ! $result || is_wp_error( $result ) ) {
407
			// error_log("There was an error sending data:");
408
			// error_log(print_r($result, 1));
409
			$result = $this->sync_queue->checkin( $buffer );
410
411
			if ( is_wp_error( $result ) ) {
412
				error_log("Error checking in buffer: ".$result->get_error_message());
413
				$this->sync_queue->force_checkin();
414
			}
415
			// try again in 1 minute
416
			$this->schedule_sync( "+1 minute" );
417
		} else {
418
419
			// scan the sent data to see if a full sync started or finished
420
			if ( $this->buffer_includes_action( $buffer, 'jetpack_full_sync_start' ) ) {
421
				$this->full_sync_client->set_status_sending_started();
422
			}
423
424
			if ( $this->buffer_includes_action( $buffer, 'jetpack_full_sync_end' ) ) {
425
				$this->full_sync_client->set_status_sending_finished();
426
			}
427
428
			$this->sync_queue->close( $buffer, count( $items_to_send ) );
429
			// check if there are any more events in the buffer
430
			// if so, schedule a cron job to happen soon
431
			if ( $this->sync_queue->has_any_items() ) {
432
				$this->schedule_sync( "+1 minute" );
433
			}
434
		}
435
	}
436
437
	private function buffer_includes_action( $buffer, $action_name ) {
438
		foreach ( $buffer->get_items() as $item ) {
439
			if ( $item[0] === $action_name ) {
440
				return true;
441
			}
442
		}
443
444
		return false;
445
	}
446
	
447
	function expand_wp_insert_post( $args ) {
448
		// list( $post_ID, $post, $update ) = $args;
449
		return array( $args[0], $this->filter_post_content( $args[1] ), $args[2] );
450
	}
451
452
	function expand_transition_post_status( $args ) {
453
		return array( $args[0], $args[1], $this->filter_post_content( $args[2] ) );
454
	}
455
	// Expands wp_insert_post to include filteredpl
456
	function filter_post_content( $post ) {
457
		if ( 0 < strlen( $post->post_password ) ) {
458
			$post->post_password = 'auto-' . wp_generate_password( 10, false );
459
		}
460
		$post->post_content_filtered = apply_filters( 'the_content', $post->post_content );
461
		return $post;
462
	}
463
464
	private function schedule_sync( $when ) {
465
		wp_schedule_single_event( strtotime( $when ), 'jetpack_sync_actions' );
466
	}
467
468
	function force_sync_constants() {
469
		delete_option( self::$constants_checksum_option_name );
470
		$this->maybe_sync_constants();
471
	}
472
473
	function force_sync_options() {
474
		do_action( 'jetpack_full_sync_options', true );
475
	}
476
477
	function force_sync_network_options() {
478
		do_action( 'jetpack_full_sync_network_options', true );
479
	}
480
481 View Code Duplication
	private function maybe_sync_constants() {
482
		$constants = $this->get_all_constants();
483
		if ( empty( $constants ) ) {
484
			return;
485
		}
486
		$constants_check_sum = $this->get_check_sum( $constants );
487
		if ( $constants_check_sum !== (int) get_option( self::$constants_checksum_option_name ) ) {
488
			do_action( 'jetpack_sync_current_constants', $constants );
489
			update_option( self::$constants_checksum_option_name, $constants_check_sum );
490
		}
491
	}
492
493
	private function get_all_constants() {
494
		return array_combine(
495
			$this->constants_whitelist,
496
			array_map( array( $this, 'get_constant' ), $this->constants_whitelist )
497
		);
498
	}
499
500
	private function get_constant( $constant ) {
501
		if ( defined( $constant ) ) {
502
			return constant( $constant );
503
		}
504
505
		return null;
506
	}
507
508
	public function force_sync_callables() {
509
		delete_option( self::$functions_checksum_option_name );
510
		$this->maybe_sync_callables();
511
	}
512
513 View Code Duplication
	private function maybe_sync_callables() {
514
		$callables = $this->get_all_callables();
515
		if ( empty( $callables ) ) {
516
			return;
517
		}
518
		$callables_check_sum = $this->get_check_sum( $callables );
519
		if ( $callables_check_sum !== (int) get_option( self::$functions_checksum_option_name ) ) {
520
			do_action( 'jetpack_sync_current_callables', $callables );
521
			update_option( self::$functions_checksum_option_name, $callables_check_sum );
522
		}
523
	}
524
525
	private function get_all_callables() {
526
		return array_combine(
527
			array_keys( $this->callable_whitelist ),
528
			array_map( array( $this, 'get_callable' ), array_values( $this->callable_whitelist ) )
529
		);
530
	}
531
532
	private function get_callable( $callable ) {
533
		return call_user_func( $callable );
534
	}
535
536
	// Is public so that we don't have to store so much data all the options twice.
537
	function get_all_options() {
538
		$options = array();
539
		foreach( $this->options_whitelist as $option ) {
540
			$options[ $option ] = get_option( $option );
541
		}
542
		return $options;
543
	}
544
545
	function get_all_network_options() {
546
		$options = array();
547
		foreach( $this->network_options_whitelist as $option ) {
548
			$options[ $option ] = get_site_option( $option );
549
		}
550
		return $options;
551
	}
552
553
	private function get_check_sum( $values ) {
554
		return crc32( serialize( $values ) );
555
	}
556
557 View Code Duplication
	function jetpack_sync_core_icon() {
558
		if ( function_exists( 'get_site_icon_url' ) ) {
559
			$url = get_site_icon_url();
560
		} else {
561
			return;
562
		}
563
564
		require_once( JETPACK__PLUGIN_DIR . 'modules/site-icon/site-icon-functions.php' );
565
		// If there's a core icon, maybe update the option.  If not, fall back to Jetpack's.
566
		if ( ! empty( $url ) && $url !== jetpack_site_icon_url() ) {
567
			// This is the option that is synced with dotcom
568
			Jetpack_Options::update_option( 'site_icon_url', $url );
569
		} else if ( empty( $url ) && did_action( 'delete_option_site_icon' ) ) {
570
			Jetpack_Options::delete_option( 'site_icon_url' );
571
		}
572
	}
573
574
	function get_sync_queue() {
575
		return $this->sync_queue;
576
	}
577
578
	function reset_sync_queue() {
579
		$this->sync_queue->reset();
580
	}
581
582
	function set_defaults() {
583
		$this->sync_queue = new Jetpack_Sync_Queue( 'sync' );
584
		$this->set_send_buffer_memory_size( Jetpack_Sync_Defaults::$default_send_buffer_memory_size );
0 ignored issues
show
Bug introduced by
The property default_send_buffer_memory_size 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...
585
		$this->set_upload_limit( Jetpack_Sync_Defaults::$default_upload_limit );
0 ignored issues
show
Bug introduced by
The property default_upload_limit 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...
586
		$this->set_full_sync_client( Jetpack_Sync_Full::getInstance() );
587
		$this->codec                     = new Jetpack_Sync_Deflate_Codec();
588
		$this->constants_whitelist       = Jetpack_Sync_Defaults::$default_constants_whitelist;
0 ignored issues
show
Bug introduced by
The property default_constants_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...
589
		$this->options_whitelist         = Jetpack_Sync_Defaults::$default_options_whitelist;
0 ignored issues
show
Bug introduced by
The property default_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...
590
		$this->network_options_whitelist = Jetpack_Sync_Defaults::$default_network_options_whitelist;
0 ignored issues
show
Bug introduced by
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...
591
		$this->taxonomy_whitelist        = Jetpack_Sync_Defaults::$default_taxonomy_whitelist;
0 ignored issues
show
Bug introduced by
The property default_taxonomy_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...
592
		$this->is_multisite              = is_multisite();
593
		
594
		// theme mod varies from theme to theme.
595
		$this->options_whitelist[] =  'theme_mods_' . get_option( 'stylesheet' );
596
		if ( $this->is_multisite ) {
597
			$this->callable_whitelist = array_merge( Jetpack_Sync_Defaults::$default_callable_whitelist, Jetpack_Sync_Defaults::$default_multisite_callable_whitelist );
0 ignored issues
show
Bug introduced by
The property default_callable_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...
Bug introduced by
The property default_multisite_callable_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...
598
		} else {
599
			$this->callable_whitelist = Jetpack_Sync_Defaults::$default_callable_whitelist;
0 ignored issues
show
Bug introduced by
The property default_callable_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...
600
		}
601
	}
602
603
	function reset_data() {
604
		delete_option( self::$constants_checksum_option_name );
605
		$this->reset_sync_queue();
606
	}
607
}
608