Completed
Push — add/sync-action ( 2198b8...45ef1e )
by
unknown
38:40 queued 29:47
created

t_status()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
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
	const CONSTANTS_CHECKSUM_OPTION_NAME = 'jetpack_constants_sync_checksum';
11
	const FUNCTIONS_CHECKSUM_OPTION_NAME = 'jetpack_functions_sync_checksum';
12
	const SYNC_THROTTLE_OPTION_NAME = 'jetpack_sync_min_wait';
13
	const LAST_SYNC_TIME_OPTION_NAME = 'jetpack_last_sync_time';
14
15
	private $checkout_memory_size;
16
	private $upload_max_bytes;
17
	private $upload_max_rows;
18
	private $sync_queue;
19
	private $full_sync_client;
20
	private $codec;
21
	private $options_whitelist;
22
	private $constants_whitelist;
23
	private $meta_types = array( 'post', 'comment' );
24
	private $callable_whitelist;
25
	private $network_options_whitelist;
26
	private $taxonomy_whitelist;
27
	private $is_multisite;
28
29
	// singleton functions
30
	private static $instance;
31
32
	public static function getInstance() {
33
		if ( null === self::$instance ) {
34
			self::$instance = new self();
35
		}
36
37
		return self::$instance;
38
	}
39
40
	// this is necessary because you can't use "new" when you declare instance properties >:(
41
	protected function __construct() {
42
		$this->set_defaults();
43
		$this->init();
44
	}
45
46
	private function init() {
47
48
		$handler = array( $this, 'action_handler' );
49
50
		/**
51
		 * Most of the following hooks are sent to the same $handler
52
		 * for immediate serialization and queuing be sent to the server.
53
		 * The only exceptions are actions which need additional processing.
54
		 */
55
56
		// constants
57
		add_action( 'jetpack_sync_current_constants', $handler, 10 );
58
59
		// functions
60
		add_action( 'jetpack_sync_current_callable', $handler, 10, 2 );
61
62
		// posts
63
		add_action( 'wp_insert_post', $handler, 10, 3 );
64
		add_action( 'deleted_post', $handler, 10 );
65
		add_filter( 'jetpack_sync_before_send_wp_insert_post', array( $this, 'expand_wp_insert_post' ) );
66
67
		// attachments
68
69
		add_action( 'edit_attachment', array( $this, 'send_attachment_info' ) );
70
		// Once we don't have to support 4.3 we can start using add_action( 'attachment_updated', $handler, 10, 3 ); instead
71
		add_action( 'add_attachment', array( $this, 'send_attachment_info' ) );
72
		add_action( 'jetpack_sync_save_add_attachment', $handler, 10, 2 );
73
74
		// comments
75
		add_action( 'wp_insert_comment', $handler, 10, 2 );
76
		add_action( 'deleted_comment', $handler, 10 );
77
		add_action( 'trashed_comment', $handler, 10 );
78
		add_action( 'spammed_comment', $handler, 10 );
79
80
		// even though it's messy, we implement these hooks because 
81
		// the edit_comment hook doesn't include the data
82
		// so this saves us a DB read for every comment event
83
		foreach ( array( '', 'trackback', 'pingback' ) as $comment_type ) {
84
			foreach ( array( 'unapproved', 'approved' ) as $comment_status ) {
85
				add_action( "comment_{$comment_status}_{$comment_type}", $handler, 10, 2 );
86
			}
87
		}
88
89
		// options
90
		add_action( 'added_option', $handler, 10, 2 );
91
		add_action( 'updated_option', $handler, 10, 3 );
92
		add_action( 'deleted_option', $handler, 10, 1 );
93
94
		// Sync Core Icon: Detect changes in Core's Site Icon and make it syncable.
95
		add_action( 'add_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) );
96
		add_action( 'update_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) );
97
		add_action( 'delete_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) );
98
99
		// wordpress version
100
		add_action( 'upgrader_process_complete', array( $this, 'send_wp_version' ), 10, 2 );
101
		add_action( 'jetpack_sync_wp_version', $handler );
102
103
		// themes
104
		add_action( 'switch_theme', array( $this, 'send_theme_info' ) );
105
		add_action( 'jetpack_sync_current_theme_support', $handler, 10 ); // custom hook, see meta-hooks below
106
107
		// post-meta, and in the future - other meta?
108
		foreach ( $this->meta_types as $meta_type ) {
109
			add_action( "added_{$meta_type}_meta", $handler, 10, 4 );
110
			add_action( "updated_{$meta_type}_meta", $handler, 10, 4 );
111
			add_action( "deleted_{$meta_type}_meta", $handler, 10, 4 );
112
		}
113
114
		// terms
115
		add_action( 'created_term', array( $this, 'save_term_handler' ), 10, 3 );
116
		add_action( 'edited_term', array( $this, 'save_term_handler' ), 10, 3 );
117
		add_action( 'jetpack_sync_save_term', $handler, 10, 4 );
118
		add_action( 'delete_term', $handler, 10, 4 );
119
		add_action( 'set_object_terms', $handler, 10, 5 );
120
		add_action( 'deleted_term_relationships', $handler, 10, 2 );
121
122
		// users
123
		add_action( 'user_register', array( $this, 'save_user_handler' ) );
124
		add_action( 'profile_update', array( $this, 'save_user_handler' ), 10, 2 );
125
		add_action( 'jetpack_sync_save_user', $handler, 10, 2 );
126
		add_action( 'deleted_user', $handler, 10, 2 );
127
128
		// user roles
129
		add_action( 'add_user_role', array( $this, 'save_user_role_handler' ), 10, 2 );
130
		add_action( 'set_user_role', array( $this, 'save_user_role_handler' ), 10, 3 );
131
		add_action( 'remove_user_role', array( $this, 'save_user_role_handler' ), 10, 2 );
132
133
134
		// user capabilities
135
		add_action( 'added_user_meta', array( $this, 'save_user_cap_handler' ), 10, 4 );
136
		add_action( 'updated_user_meta', array( $this, 'save_user_cap_handler' ), 10, 4 );
137
		add_action( 'deleted_user_meta', array( $this, 'save_user_cap_handler' ), 10, 4 );
138
139
		// themes
140
		add_action( 'set_site_transient_update_plugins', $handler, 10, 1 );
141
		add_action( 'set_site_transient_update_themes', $handler, 10, 1 );
142
		add_action( 'set_site_transient_update_core', $handler, 10, 1 );
143
144
		// multi site network options
145
		if ( $this->is_multisite ) {
146
			add_action( 'add_site_option', $handler, 10, 2 );
147
			add_action( 'update_site_option', $handler, 10, 3 );
148
			add_action( 'delete_site_option', $handler, 10, 1 );
149
		}
150
151
		// synthetic actions for full sync
152
		add_action( 'jetpack_full_sync_start', $handler );
153
		add_action( 'jetpack_full_sync_end', $handler );
154
		add_action( 'jetpack_full_sync_options', $handler );
155
		add_action( 'jetpack_full_sync_posts', $handler ); // also sends post meta
156
		add_action( 'jetpack_full_sync_comments', $handler ); // also send comments meta
157
		add_action( 'jetpack_full_sync_users', $handler );
158
		add_action( 'jetpack_full_sync_terms', $handler, 10, 2 );
159
		if ( is_multisite() ) {
160
			add_action( 'jetpack_full_sync_network_options', $handler );
161
		}
162
163
164
		// 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...
165
166
		/**
167
		 * Sync all pending actions with server
168
		 */
169
		add_action( 'jetpack_sync_actions', array( $this, 'do_sync' ) );
170
	}
171
172
	// 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...
173
	function set_options_whitelist( $options ) {
174
		$this->options_whitelist = $options;
175
	}
176
177
	function set_constants_whitelist( $constants ) {
178
		$this->constants_whitelist = $constants;
179
	}
180
181
	function get_callable_whitelist() {
182
		return $this->callable_whitelist;
183
	}
184
185
	function set_callable_whitelist( $functions ) {
186
		$this->callable_whitelist = $functions;
187
	}
188
189
	function set_network_options_whitelist( $options ) {
190
		$this->network_options_whitelist = $options;
191
	}
192
193
	function set_send_buffer_memory_size( $size ) {
194
		$this->checkout_memory_size = $size;
195
	}
196
197
	// in bytes
198
	function set_upload_max_bytes( $max_bytes ) {
199
		$this->upload_max_bytes = $max_bytes;
200
	}
201
202
	// in rows
203
	function set_upload_max_rows( $max_rows ) {
204
		$this->upload_max_rows = $max_rows;
205
	}
206
207
	// in seconds
208
	function set_min_sync_wait_time( $seconds ) {
209
		update_option( self::SYNC_THROTTLE_OPTION_NAME, $seconds, true );
210
	}
211
212
	function get_min_sync_wait_time() {
213
		return get_option( self::SYNC_THROTTLE_OPTION_NAME );
214
	}
215
216
	private function get_last_sync_time() {
217
		return (double) get_option( self::LAST_SYNC_TIME_OPTION_NAME );
218
	}
219
220
	private function set_last_sync_time() {
221
		return update_option( self::LAST_SYNC_TIME_OPTION_NAME, microtime(true), true );
222
	}
223
224
	function set_taxonomy_whitelist( $taxonomies ) {
225
		$this->taxonomy_whitelist = $taxonomies;
226
	}
227
228
	function is_whitelisted_option( $option ) {
229
		return in_array( $option, $this->options_whitelist );
230
	}
231
232
	function is_whitelisted_network_option( $option ) {
233
		return $this->is_multisite && in_array( $option, $this->network_options_whitelist );
234
	}
235
236
	function set_codec( iJetpack_Sync_Codec $codec ) {
237
		$this->codec = $codec;
238
	}
239
240
	function set_full_sync_client( $full_sync_client ) {
241
		if ( $this->full_sync_client ) {
242
			remove_action( 'jetpack_sync_full', array( $this->full_sync_client, 'start' ) );
243
		}
244
245
		$this->full_sync_client = $full_sync_client;
246
247
		/**
248
		 * Sync all objects in the database with the server
249
		 */
250
		add_action( 'jetpack_sync_full', array( $this->full_sync_client, 'start' ) );
251
	}
252
253
	function get_full_sync_client() {
254
		return $this->full_sync_client;
255
	}
256
257
	function action_handler() {
258
		// 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...
259
		// wherever we initialize the action listeners or we're just wasting cycles
260
		if ( Jetpack::is_development_mode() || Jetpack::is_staging_site() ) {
261
			return false;
262
		}
263
264
		$current_filter = current_filter();
265
		$args           = func_get_args();
266
267
		if ( $current_filter === 'wp_insert_post' && $args[1]->post_type === 'revision' ) {
268
			return;
269
		}
270
271
		if ( in_array( $current_filter, array( 'deleted_option', 'added_option', 'updated_option' ) )
272
		     &&
273
		     ! $this->is_whitelisted_option( $args[0] )
274
		) {
275
			return;
276
		}
277
278
		if ( in_array( $current_filter, array( 'delete_site_option', 'add_site_option', 'update_site_option' ) )
279
		     &&
280
		     ! $this->is_whitelisted_network_option( $args[0] )
281
		) {
282
			return;
283
		}
284
285
		// don't sync private meta
286
		if ( preg_match( '/^(added|updated|deleted)_.*_meta$/', $current_filter )
287
		     && $args[2][0] === '_'
288
		     && ! 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...
289
		) {
290
			return;
291
		}
292
293
		$this->sync_queue->add( array(
294
			$current_filter,
295
			$args,
296
			get_current_user_id(),
297
			microtime( true )
298
		) );
299
	}
300
301
	function send_theme_info() {
302
		global $_wp_theme_features;
303
304
		$theme_support = array();
305
306
		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...
307
			$has_support = current_theme_supports( $theme_feature );
308
			if ( $has_support ) {
309
				$theme_support[ $theme_feature ] = $_wp_theme_features[ $theme_feature ];
310
			}
311
312
		}
313
		do_action( 'jetpack_sync_current_theme_support', $theme_support );
314
	}
315
316
	function send_wp_version( $update, $meta_data ) {
317
		if ( 'update' === $meta_data['action'] && 'core' === $meta_data['type'] ) {
318
			global $wp_version;
319
			do_action( 'jetpack_sync_wp_version', $wp_version );
320
		}
321
	}
322
323
	function save_term_handler( $term_id, $tt_id, $taxonomy ) {
324
		if ( class_exists( 'WP_Term' ) ) {
325
			$term_object = WP_Term::get_instance( $term_id, $taxonomy );
326
		} else {
327
			$term_object = get_term_by( 'id', $term_id, $taxonomy );
328
		}
329
330
		do_action( 'jetpack_sync_save_term', $term_object );
331
	}
332
333
	function send_attachment_info( $attachment_id ) {
334
		$attachment = get_post( $attachment_id );
335
		do_action( 'jetpack_sync_save_add_attachment', $attachment_id, $attachment );
336
	}
337
338
	function save_user_handler( $user_id, $old_user_data = null ) {
339
		$user = $this->sanitize_user( get_user_by( 'id', $user_id ) );
340
341
		// Older versions of WP don't pass the old_user_data in ->data
342
		if ( isset( $old_user_data->data ) ) {
343
			$old_user = $old_user_data->data;
344
		} else {
345
			$old_user = $old_user_data;
346
		}
347
348
		if ( $old_user !== null ) {
349
			unset( $old_user->user_pass );
350
			if ( serialize( $old_user ) === serialize( $user->data ) ) {
351
				return;
352
			}
353
		}
354
		do_action( 'jetpack_sync_save_user', $user );
355
	}
356
357
	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...
358
		$user = $this->sanitize_user( get_user_by( 'id', $user_id ) );
359
		do_action( 'jetpack_sync_save_user', $user );
360
	}
361
362
	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...
363
		$user = $this->sanitize_user( get_user_by( 'id', $user_id ) );
364
		if ( $meta_key === $user->cap_key ) {
365
			do_action( 'jetpack_sync_save_user', $user );
366
		}
367
	}
368
369
	public function sanitize_user( $user ) {
370
		unset( $user->data->user_pass );
371
372
		return $user;
373
	}
374
375
376
	function do_sync() {
377
		// don't sync if importing
378
		if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
379
			$this->schedule_sync( "+1 minute" );
380
381
			return false;
382
		}
383
384
		// don't sync if we are throttled
385
		$sync_wait = $this->get_min_sync_wait_time();
386
		$last_sync = $this->get_last_sync_time();
387
388
		if ( $last_sync && $sync_wait && $last_sync + $sync_wait > microtime( true ) ) {
389
			return false;
390
		}
391
392
		$this->set_last_sync_time();
393
		$this->maybe_sync_constants();
394
		$this->maybe_sync_callables();
395
396
		if ( $this->sync_queue->size() === 0 ) {
397
			return false;
398
		}
399
400
		$buffer = $this->sync_queue->checkout_with_memory_limit( $this->checkout_memory_size, $this->upload_max_rows );
401
402
		if ( ! $buffer ) {
403
			// buffer has no items
404
			return false;
405
		}
406
407
		if ( is_wp_error( $buffer ) ) {
408
			// another buffer is currently sending
409
			return false;
410
		}
411
412
		$upload_size   = 0;
413
		$items_to_send = array();
414
415
		// we estimate the total encoded size as we go by encoding each item individually
416
		// this is expensive, but the only way to really know :/
417
		foreach ( $buffer->get_items() as $key => $item ) {
418
419
			// expand item data, e.g. IDs into posts (for full sync)
420
			$item[1] = apply_filters( "jetpack_sync_before_send_" . $item[0], $item[1] );
421
422
			$encoded_item = $this->codec->encode( $item );
423
			$upload_size += strlen( $encoded_item );
424
425
			if ( $upload_size > $this->upload_max_bytes && count( $items_to_send ) > 0 ) {
426
				break;
427
			}
428
429
			$items_to_send[ $key ] = $encoded_item;
430
		}
431
432
		/**
433
		 * Fires when data is ready to send to the server.
434
		 * Return false or WP_Error to abort the sync (e.g. if there's an error)
435
		 * The items will be automatically re-sent later
436
		 *
437
		 * @since 4.1
438
		 *
439
		 * @param array $data The action buffer
440
		 */
441
		$result = apply_filters( 'jetpack_sync_client_send_data', $items_to_send );
442
443
		if ( ! $result || is_wp_error( $result ) ) {
444
			// error_log("There was an error sending data:");
445
			// error_log(print_r($result, 1));
446
			$result = $this->sync_queue->checkin( $buffer );
447
448
			if ( is_wp_error( $result ) ) {
449
				error_log( "Error checking in buffer: " . $result->get_error_message() );
450
				$this->sync_queue->force_checkin();
451
			}
452
			// try again in 1 minute
453
			$this->schedule_sync( "+1 minute" );
454
		} else {
455
456
			// scan the sent data to see if a full sync started or finished
457
			if ( $this->buffer_includes_action( $buffer, 'jetpack_full_sync_start' ) ) {
458
				$this->full_sync_client->set_status_sending_started();
459
			}
460
461
			if ( $this->buffer_includes_action( $buffer, 'jetpack_full_sync_end' ) ) {
462
				$this->full_sync_client->set_status_sending_finished();
463
			}
464
465
			$this->sync_queue->close( $buffer, $result );
466
			// check if there are any more events in the buffer
467
			// if so, schedule a cron job to happen soon
468
			if ( $this->sync_queue->has_any_items() ) {
469
				$this->schedule_sync( "+1 minute" );
470
			}
471
		}
472
	}
473
474
	private function buffer_includes_action( $buffer, $action_name ) {
475
		foreach ( $buffer->get_items() as $item ) {
476
			if ( $item[0] === $action_name ) {
477
				return true;
478
			}
479
		}
480
481
		return false;
482
	}
483
484
	function expand_wp_insert_post( $args ) {
485
		// list( $post_ID, $post, $update ) = $args;
486
		return array( $args[0], $this->filter_post_content( $args[1] ), $args[2] );
487
	}
488
489
	// Expands wp_insert_post to include filteredpl
490
	function filter_post_content( $post ) {
491
		if ( 0 < strlen( $post->post_password ) ) {
492
			$post->post_password = 'auto-' . wp_generate_password( 10, false );
493
		}
494
		$post->post_content_filtered = apply_filters( 'the_content', $post->post_content );
495
496
		return $post;
497
	}
498
499
	private function schedule_sync( $when ) {
500
		wp_schedule_single_event( strtotime( $when ), 'jetpack_sync_actions' );
501
	}
502
503
	function force_sync_constants() {
504
		delete_option( self::CONSTANTS_CHECKSUM_OPTION_NAME );
505
		$this->maybe_sync_constants();
506
	}
507
508
	function force_sync_options() {
509
		do_action( 'jetpack_full_sync_options', true );
510
	}
511
512
	function force_sync_network_options() {
513
		do_action( 'jetpack_full_sync_network_options', true );
514
	}
515
516
	private function maybe_sync_constants() {
517
		$constants = $this->get_all_constants();
518
		if ( empty( $constants ) ) {
519
			return;
520
		}
521
		$constants_check_sum = $this->get_check_sum( $constants );
522
		if ( $constants_check_sum !== (int) get_option( self::CONSTANTS_CHECKSUM_OPTION_NAME ) ) {
523
			do_action( 'jetpack_sync_current_constants', $constants );
524
			update_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, $constants_check_sum );
525
		}
526
	}
527
528
	private function get_all_constants() {
529
		return array_combine(
530
			$this->constants_whitelist,
531
			array_map( array( $this, 'get_constant' ), $this->constants_whitelist )
532
		);
533
	}
534
535
	private function get_constant( $constant ) {
536
		if ( defined( $constant ) ) {
537
			return constant( $constant );
538
		}
539
540
		return null;
541
	}
542
543
	public function force_sync_callables() {
544
		foreach ( $this->callable_whitelist as $name => $config ) {
545
			delete_option( self::FUNCTIONS_CHECKSUM_OPTION_NAME."_$name" );
546
		}
547
		
548
		$this->maybe_sync_callables();
549
	}
550
551
	private function maybe_sync_callables() {
552
		$callables = $this->get_all_callables();
553
		if ( empty( $callables ) ) {
554
			return;
555
		}
556
557
		// only send the callables that have changed
558
		foreach ( $callables as $name => $value ) {
559
			$checksum = $this->get_check_sum( $value );
560
			// explicitly not using Identical comparison as get_option returns a string
561
			if ( $checksum != get_option( self::FUNCTIONS_CHECKSUM_OPTION_NAME . "_$name" ) ) {
562
				do_action( 'jetpack_sync_current_callable', $name, $value );
563
				update_option( self::FUNCTIONS_CHECKSUM_OPTION_NAME . "_$name", $checksum );
564
			}
565
		}
566
	}
567
568
	private function get_all_callables() {
569
		return array_combine(
570
			array_keys( $this->callable_whitelist ),
571
			array_map( array( $this, 'get_callable' ), array_values( $this->callable_whitelist ) )
572
		);
573
	}
574
575
	private function get_callable( $callable ) {
576
		return call_user_func( $callable );
577
	}
578
579
	// Is public so that we don't have to store so much data all the options twice.
580
	function get_all_options() {
581
		$options = array();
582
		foreach ( $this->options_whitelist as $option ) {
583
			$options[ $option ] = get_option( $option );
584
		}
585
586
		return $options;
587
	}
588
589
	function get_all_network_options() {
590
		$options = array();
591
		foreach ( $this->network_options_whitelist as $option ) {
592
			$options[ $option ] = get_site_option( $option );
593
		}
594
595
		return $options;
596
	}
597
598
	private function get_check_sum( $values ) {
599
		return crc32( serialize( $values ) );
600
	}
601
602 View Code Duplication
	function jetpack_sync_core_icon() {
603
		if ( function_exists( 'get_site_icon_url' ) ) {
604
			$url = get_site_icon_url();
605
		} else {
606
			return;
607
		}
608
609
		require_once( JETPACK__PLUGIN_DIR . 'modules/site-icon/site-icon-functions.php' );
610
		// If there's a core icon, maybe update the option.  If not, fall back to Jetpack's.
611
		if ( ! empty( $url ) && $url !== jetpack_site_icon_url() ) {
612
			// This is the option that is synced with dotcom
613
			Jetpack_Options::update_option( 'site_icon_url', $url );
614
		} else if ( empty( $url ) && did_action( 'delete_option_site_icon' ) ) {
615
			Jetpack_Options::delete_option( 'site_icon_url' );
616
		}
617
	}
618
619
	function get_sync_queue() {
620
		return $this->sync_queue;
621
	}
622
623
	function reset_sync_queue() {
624
		$this->sync_queue->reset();
625
	}
626
627
	function set_defaults() {
628
		$this->sync_queue = new Jetpack_Sync_Queue( 'sync' );
629
		$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...
630
		$this->set_upload_max_bytes( Jetpack_Sync_Defaults::$default_upload_max_bytes );
0 ignored issues
show
Bug introduced by
The property default_upload_max_bytes 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...
631
		$this->set_upload_max_rows( Jetpack_Sync_Defaults::$default_upload_max_rows );
0 ignored issues
show
Bug introduced by
The property default_upload_max_rows 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...
632
633
		if ( $this->get_min_sync_wait_time() === false ) {
634
			$this->set_min_sync_wait_time( Jetpack_Sync_Defaults::$default_sync_wait_time );
0 ignored issues
show
Bug introduced by
The property default_sync_wait_time 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...
635
		}
636
637
		$this->set_full_sync_client( Jetpack_Sync_Full::getInstance() );
638
		$this->codec                     = new Jetpack_Sync_Deflate_Codec();
639
		$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...
640
		$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...
641
		$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...
642
		$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...
643
		$this->is_multisite              = is_multisite();
644
645
		// theme mod varies from theme to theme.
646
		$this->options_whitelist[] = 'theme_mods_' . get_option( 'stylesheet' );
647
		if ( $this->is_multisite ) {
648
			$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...
649
		} else {
650
			$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...
651
		}
652
	}
653
654
	function reset_data() {
655
		delete_option( self::CONSTANTS_CHECKSUM_OPTION_NAME );
656
		$this->reset_sync_queue();
657
	}
658
}
659