Completed
Push — add/sync-action ( d5ee32...c4907d )
by
unknown
18:08 queued 09:17
created

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