Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Jetpack_Sync_Client often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Jetpack_Sync_Client, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 8 | class Jetpack_Sync_Client { |
||
| 9 | |||
| 10 | const CONSTANTS_CHECKSUM_OPTION_NAME = 'jetpack_constants_sync_checksum'; |
||
| 11 | const CALLABLES_CHECKSUM_OPTION_NAME = 'jetpack_callables_sync_checksum'; |
||
| 12 | const SYNC_THROTTLE_OPTION_NAME = 'jetpack_sync_min_wait'; |
||
| 13 | const LAST_SYNC_TIME_OPTION_NAME = 'jetpack_last_sync_time'; |
||
| 14 | const CALLABLES_AWAIT_TRANSIENT_NAME = 'jetpack_sync_callables_await'; |
||
| 15 | const CONSTANTS_AWAIT_TRANSIENT_NAME = 'jetpack_sync_constants_await'; |
||
| 16 | |||
| 17 | private $checkout_memory_size; |
||
| 18 | private $upload_max_bytes; |
||
| 19 | private $upload_max_rows; |
||
| 20 | private $sync_queue; |
||
| 21 | private $full_sync_client; |
||
| 22 | private $codec; |
||
| 23 | private $options_whitelist; |
||
| 24 | private $constants_whitelist; |
||
| 25 | private $meta_types = array( 'post', 'comment' ); |
||
| 26 | private $callable_whitelist; |
||
| 27 | private $network_options_whitelist; |
||
| 28 | private $taxonomy_whitelist; |
||
| 29 | private $is_multisite; |
||
| 30 | |||
| 31 | // singleton functions |
||
| 32 | private static $instance; |
||
| 33 | |||
| 34 | public static function getInstance() { |
||
| 35 | if ( null === self::$instance ) { |
||
| 36 | self::$instance = new self(); |
||
| 37 | } |
||
| 38 | |||
| 39 | return self::$instance; |
||
| 40 | } |
||
| 41 | |||
| 42 | // this is necessary because you can't use "new" when you declare instance properties >:( |
||
| 43 | protected function __construct() { |
||
| 44 | $this->set_defaults(); |
||
| 45 | $this->init(); |
||
| 46 | } |
||
| 47 | |||
| 48 | private function init() { |
||
| 49 | |||
| 50 | $handler = array( $this, 'action_handler' ); |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Most of the following hooks are sent to the same $handler |
||
| 54 | * for immediate serialization and queuing be sent to the server. |
||
| 55 | * The only exceptions are actions which need additional processing. |
||
| 56 | */ |
||
| 57 | |||
| 58 | // constants |
||
| 59 | add_action( 'jetpack_sync_constant', $handler, 10, 2 ); |
||
| 60 | |||
| 61 | // callables |
||
| 62 | add_action( 'jetpack_sync_callable', $handler, 10, 2 ); |
||
| 63 | |||
| 64 | // posts |
||
| 65 | add_action( 'wp_insert_post', $handler, 10, 3 ); |
||
| 66 | add_action( 'deleted_post', $handler, 10 ); |
||
| 67 | add_filter( 'jetpack_sync_before_send_wp_insert_post', array( $this, 'expand_wp_insert_post' ) ); |
||
| 68 | |||
| 69 | add_action( 'jetpack_publicize_post', $handler ); |
||
| 70 | |||
| 71 | // attachments |
||
| 72 | |||
| 73 | add_action( 'edit_attachment', array( $this, 'send_attachment_info' ) ); |
||
| 74 | // Once we don't have to support 4.3 we can start using add_action( 'attachment_updated', $handler, 10, 3 ); instead |
||
| 75 | add_action( 'add_attachment', array( $this, 'send_attachment_info' ) ); |
||
| 76 | add_action( 'jetpack_sync_save_add_attachment', $handler, 10, 2 ); |
||
| 77 | |||
| 78 | // comments |
||
| 79 | add_action( 'wp_insert_comment', $handler, 10, 2 ); |
||
| 80 | add_action( 'deleted_comment', $handler, 10 ); |
||
| 81 | add_action( 'trashed_comment', $handler, 10 ); |
||
| 82 | add_action( 'spammed_comment', $handler, 10 ); |
||
| 83 | |||
| 84 | // even though it's messy, we implement these hooks because |
||
| 85 | // the edit_comment hook doesn't include the data |
||
| 86 | // so this saves us a DB read for every comment event |
||
| 87 | foreach ( array( '', 'trackback', 'pingback' ) as $comment_type ) { |
||
| 88 | foreach ( array( 'unapproved', 'approved' ) as $comment_status ) { |
||
| 89 | add_action( "comment_{$comment_status}_{$comment_type}", $handler, 10, 2 ); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | // options |
||
| 94 | add_action( 'added_option', $handler, 10, 2 ); |
||
| 95 | add_action( 'updated_option', $handler, 10, 3 ); |
||
| 96 | add_action( 'deleted_option', $handler, 10, 1 ); |
||
| 97 | |||
| 98 | // Sync Core Icon: Detect changes in Core's Site Icon and make it syncable. |
||
| 99 | add_action( 'add_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); |
||
| 100 | add_action( 'update_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); |
||
| 101 | add_action( 'delete_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); |
||
| 102 | |||
| 103 | // wordpress version |
||
| 104 | add_action( 'upgrader_process_complete', array( $this, 'send_wp_version' ), 10, 2 ); |
||
| 105 | add_action( 'jetpack_sync_wp_version', $handler ); |
||
| 106 | |||
| 107 | // themes |
||
| 108 | add_action( 'switch_theme', array( $this, 'send_theme_info' ) ); |
||
| 109 | add_action( 'jetpack_sync_current_theme_support', $handler, 10 ); // custom hook, see meta-hooks below |
||
| 110 | |||
| 111 | // post-meta, and in the future - other meta? |
||
| 112 | foreach ( $this->meta_types as $meta_type ) { |
||
| 113 | add_action( "added_{$meta_type}_meta", $handler, 10, 4 ); |
||
| 114 | add_action( "updated_{$meta_type}_meta", $handler, 10, 4 ); |
||
| 115 | add_action( "deleted_{$meta_type}_meta", $handler, 10, 4 ); |
||
| 116 | } |
||
| 117 | |||
| 118 | // terms |
||
| 119 | add_action( 'created_term', array( $this, 'save_term_handler' ), 10, 3 ); |
||
| 120 | add_action( 'edited_term', array( $this, 'save_term_handler' ), 10, 3 ); |
||
| 121 | add_action( 'jetpack_sync_save_term', $handler, 10, 4 ); |
||
| 122 | add_action( 'delete_term', $handler, 10, 4 ); |
||
| 123 | add_action( 'set_object_terms', $handler, 10, 6 ); |
||
| 124 | add_action( 'deleted_term_relationships', $handler, 10, 2 ); |
||
| 125 | |||
| 126 | // users |
||
| 127 | add_action( 'user_register', array( $this, 'save_user_handler' ) ); |
||
| 128 | add_action( 'profile_update', array( $this, 'save_user_handler' ), 10, 2 ); |
||
| 129 | add_action( 'jetpack_sync_save_user', $handler, 10, 2 ); |
||
| 130 | add_action( 'deleted_user', $handler, 10, 2 ); |
||
| 131 | |||
| 132 | // user roles |
||
| 133 | add_action( 'add_user_role', array( $this, 'save_user_role_handler' ), 10, 2 ); |
||
| 134 | add_action( 'set_user_role', array( $this, 'save_user_role_handler' ), 10, 3 ); |
||
| 135 | add_action( 'remove_user_role', array( $this, 'save_user_role_handler' ), 10, 2 ); |
||
| 136 | |||
| 137 | |||
| 138 | // user capabilities |
||
| 139 | add_action( 'added_user_meta', array( $this, 'save_user_cap_handler' ), 10, 4 ); |
||
| 140 | add_action( 'updated_user_meta', array( $this, 'save_user_cap_handler' ), 10, 4 ); |
||
| 141 | add_action( 'deleted_user_meta', array( $this, 'save_user_cap_handler' ), 10, 4 ); |
||
| 142 | |||
| 143 | // themes |
||
| 144 | add_action( 'set_site_transient_update_plugins', $handler, 10, 1 ); |
||
| 145 | add_action( 'set_site_transient_update_themes', $handler, 10, 1 ); |
||
| 146 | add_action( 'set_site_transient_update_core', $handler, 10, 1 ); |
||
| 147 | |||
| 148 | // multi site network options |
||
| 149 | if ( $this->is_multisite ) { |
||
| 150 | add_action( 'add_site_option', $handler, 10, 2 ); |
||
| 151 | add_action( 'update_site_option', $handler, 10, 3 ); |
||
| 152 | add_action( 'delete_site_option', $handler, 10, 1 ); |
||
| 153 | } |
||
| 154 | |||
| 155 | // synthetic actions for full sync |
||
| 156 | add_action( 'jetpack_full_sync_start', $handler ); |
||
| 157 | add_action( 'jetpack_full_sync_end', $handler ); |
||
| 158 | add_action( 'jetpack_full_sync_options', $handler ); |
||
| 159 | add_action( 'jetpack_full_sync_posts', $handler ); // also sends post meta |
||
| 160 | add_action( 'jetpack_full_sync_comments', $handler ); // also send comments meta |
||
| 161 | add_action( 'jetpack_full_sync_users', $handler ); |
||
| 162 | add_action( 'jetpack_full_sync_terms', $handler, 10, 2 ); |
||
| 163 | if ( is_multisite() ) { |
||
| 164 | add_action( 'jetpack_full_sync_network_options', $handler ); |
||
| 165 | } |
||
| 166 | |||
| 167 | |||
| 168 | // TODO: Callables, Constanst, Network Options, Users, Terms |
||
|
|
|||
| 169 | |||
| 170 | /** |
||
| 171 | * Sync all pending actions with server |
||
| 172 | */ |
||
| 173 | add_action( 'jetpack_sync_actions', array( $this, 'do_sync' ) ); |
||
| 174 | } |
||
| 175 | |||
| 176 | // TODO: Refactor to use one set whitelist function, with one is_whitelisted. |
||
| 177 | function set_options_whitelist( $options ) { |
||
| 178 | $this->options_whitelist = $options; |
||
| 179 | } |
||
| 180 | |||
| 181 | function set_constants_whitelist( $constants ) { |
||
| 182 | $this->constants_whitelist = $constants; |
||
| 183 | } |
||
| 184 | |||
| 185 | function get_callable_whitelist() { |
||
| 186 | return $this->callable_whitelist; |
||
| 187 | } |
||
| 188 | |||
| 189 | function set_callable_whitelist( $callables ) { |
||
| 192 | |||
| 193 | function set_network_options_whitelist( $options ) { |
||
| 194 | $this->network_options_whitelist = $options; |
||
| 195 | } |
||
| 196 | |||
| 197 | function set_send_buffer_memory_size( $size ) { |
||
| 198 | $this->checkout_memory_size = $size; |
||
| 199 | } |
||
| 200 | |||
| 201 | // in bytes |
||
| 202 | function set_upload_max_bytes( $max_bytes ) { |
||
| 203 | $this->upload_max_bytes = $max_bytes; |
||
| 204 | } |
||
| 205 | |||
| 206 | // in rows |
||
| 207 | function set_upload_max_rows( $max_rows ) { |
||
| 208 | $this->upload_max_rows = $max_rows; |
||
| 209 | } |
||
| 210 | |||
| 211 | // in seconds |
||
| 212 | function set_min_sync_wait_time( $seconds ) { |
||
| 213 | update_option( self::SYNC_THROTTLE_OPTION_NAME, $seconds, true ); |
||
| 214 | } |
||
| 215 | |||
| 216 | function get_min_sync_wait_time() { |
||
| 217 | return get_option( self::SYNC_THROTTLE_OPTION_NAME ); |
||
| 218 | } |
||
| 219 | |||
| 220 | private function get_last_sync_time() { |
||
| 221 | return (double) get_option( self::LAST_SYNC_TIME_OPTION_NAME ); |
||
| 222 | } |
||
| 223 | |||
| 224 | private function set_last_sync_time() { |
||
| 225 | return update_option( self::LAST_SYNC_TIME_OPTION_NAME, microtime( true ), true ); |
||
| 226 | } |
||
| 227 | |||
| 228 | function set_taxonomy_whitelist( $taxonomies ) { |
||
| 229 | $this->taxonomy_whitelist = $taxonomies; |
||
| 230 | } |
||
| 231 | |||
| 232 | function is_whitelisted_option( $option ) { |
||
| 233 | return in_array( $option, $this->options_whitelist ); |
||
| 234 | } |
||
| 235 | |||
| 236 | function is_whitelisted_network_option( $option ) { |
||
| 237 | return $this->is_multisite && in_array( $option, $this->network_options_whitelist ); |
||
| 238 | } |
||
| 239 | |||
| 240 | function set_codec( iJetpack_Sync_Codec $codec ) { |
||
| 241 | $this->codec = $codec; |
||
| 242 | } |
||
| 243 | |||
| 244 | function set_full_sync_client( $full_sync_client ) { |
||
| 245 | if ( $this->full_sync_client ) { |
||
| 246 | remove_action( 'jetpack_sync_full', array( $this->full_sync_client, 'start' ) ); |
||
| 247 | } |
||
| 248 | |||
| 249 | $this->full_sync_client = $full_sync_client; |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Sync all objects in the database with the server |
||
| 253 | */ |
||
| 254 | add_action( 'jetpack_sync_full', array( $this->full_sync_client, 'start' ) ); |
||
| 255 | } |
||
| 256 | |||
| 257 | function get_full_sync_client() { |
||
| 258 | return $this->full_sync_client; |
||
| 259 | } |
||
| 260 | |||
| 261 | function action_handler() { |
||
| 262 | // TODO: it's really silly to have this function here - it should be |
||
| 263 | // wherever we initialize the action listeners or we're just wasting cycles |
||
| 264 | if ( Jetpack::is_development_mode() || Jetpack::is_staging_site() ) { |
||
| 265 | return false; |
||
| 266 | } |
||
| 267 | |||
| 268 | $current_filter = current_filter(); |
||
| 269 | $args = func_get_args(); |
||
| 270 | |||
| 271 | if ( $current_filter === 'wp_insert_post' && $args[1]->post_type === 'revision' ) { |
||
| 272 | return; |
||
| 273 | } |
||
| 274 | |||
| 275 | if ( in_array( $current_filter, array( 'deleted_option', 'added_option', 'updated_option' ) ) |
||
| 276 | && |
||
| 277 | ! $this->is_whitelisted_option( $args[0] ) |
||
| 278 | ) { |
||
| 279 | return; |
||
| 280 | } |
||
| 281 | |||
| 282 | if ( in_array( $current_filter, array( 'delete_site_option', 'add_site_option', 'update_site_option' ) ) |
||
| 283 | && |
||
| 284 | ! $this->is_whitelisted_network_option( $args[0] ) |
||
| 285 | ) { |
||
| 286 | return; |
||
| 287 | } |
||
| 288 | |||
| 289 | // don't sync private meta |
||
| 290 | if ( preg_match( '/^(added|updated|deleted)_.*_meta$/', $current_filter ) |
||
| 291 | && $args[2][0] === '_' |
||
| 292 | && ! in_array( $args[2], Jetpack_Sync_Defaults::$default_whitelist_meta_keys ) |
||
| 293 | ) { |
||
| 294 | return; |
||
| 295 | } |
||
| 296 | |||
| 297 | $this->sync_queue->add( array( |
||
| 298 | $current_filter, |
||
| 299 | $args, |
||
| 300 | get_current_user_id(), |
||
| 301 | microtime( true ) |
||
| 302 | ) ); |
||
| 303 | } |
||
| 304 | |||
| 305 | function send_theme_info() { |
||
| 328 | |||
| 329 | function send_wp_version( $update, $meta_data ) { |
||
| 343 | |||
| 344 | function save_term_handler( $term_id, $tt_id, $taxonomy ) { |
||
| 360 | |||
| 361 | function send_attachment_info( $attachment_id ) { |
||
| 374 | |||
| 375 | function save_user_handler( $user_id, $old_user_data = null ) { |
||
| 401 | |||
| 402 | function save_user_role_handler( $user_id, $role, $old_roles = null ) { |
||
| 414 | |||
| 415 | function save_user_cap_handler( $meta_id, $user_id, $meta_key, $capabilities ) { |
||
| 428 | |||
| 429 | public function sanitize_user( $user ) { |
||
| 430 | unset( $user->data->user_pass ); |
||
| 431 | |||
| 432 | return $user; |
||
| 433 | } |
||
| 434 | |||
| 435 | |||
| 436 | function do_sync() { |
||
| 437 | // don't sync if importing |
||
| 438 | if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { |
||
| 439 | $this->schedule_sync( "+1 minute" ); |
||
| 440 | |||
| 441 | return false; |
||
| 442 | } |
||
| 443 | |||
| 444 | // don't sync if we are throttled |
||
| 445 | $sync_wait = $this->get_min_sync_wait_time(); |
||
| 446 | $last_sync = $this->get_last_sync_time(); |
||
| 447 | |||
| 448 | if ( $last_sync && $sync_wait && $last_sync + $sync_wait > microtime( true ) ) { |
||
| 449 | return false; |
||
| 450 | } |
||
| 451 | |||
| 452 | $this->set_last_sync_time(); |
||
| 453 | $this->maybe_sync_constants(); |
||
| 454 | $this->maybe_sync_callables(); |
||
| 455 | |||
| 456 | if ( $this->sync_queue->size() === 0 ) { |
||
| 457 | return false; |
||
| 458 | } |
||
| 459 | |||
| 460 | $buffer = $this->sync_queue->checkout_with_memory_limit( $this->checkout_memory_size, $this->upload_max_rows ); |
||
| 461 | |||
| 462 | if ( ! $buffer ) { |
||
| 463 | // buffer has no items |
||
| 464 | return false; |
||
| 465 | } |
||
| 466 | |||
| 467 | if ( is_wp_error( $buffer ) ) { |
||
| 468 | // another buffer is currently sending |
||
| 469 | return false; |
||
| 470 | } |
||
| 471 | |||
| 472 | $upload_size = 0; |
||
| 473 | $items_to_send = array(); |
||
| 474 | |||
| 475 | // we estimate the total encoded size as we go by encoding each item individually |
||
| 476 | // this is expensive, but the only way to really know :/ |
||
| 477 | foreach ( $buffer->get_items() as $key => $item ) { |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Modify the data within an action before it is serialized and sent to the server |
||
| 481 | * For example, during full sync this expands Post ID's into full Post objects, |
||
| 482 | * so that we don't have to serialize the whole object into the queue. |
||
| 483 | * |
||
| 484 | * @since 4.1.0 |
||
| 485 | * |
||
| 486 | * @param array The action parameters |
||
| 487 | */ |
||
| 488 | $item[1] = apply_filters( "jetpack_sync_before_send_" . $item[0], $item[1] ); |
||
| 489 | |||
| 490 | $encoded_item = $this->codec->encode( $item ); |
||
| 491 | $upload_size += strlen( $encoded_item ); |
||
| 492 | |||
| 493 | if ( $upload_size > $this->upload_max_bytes && count( $items_to_send ) > 0 ) { |
||
| 494 | break; |
||
| 495 | } |
||
| 496 | |||
| 497 | $items_to_send[ $key ] = $encoded_item; |
||
| 498 | } |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Fires when data is ready to send to the server. |
||
| 502 | * Return false or WP_Error to abort the sync (e.g. if there's an error) |
||
| 503 | * The items will be automatically re-sent later |
||
| 504 | * |
||
| 505 | * @since 4.1 |
||
| 506 | * |
||
| 507 | * @param array $data The action buffer |
||
| 508 | */ |
||
| 509 | $result = apply_filters( 'jetpack_sync_client_send_data', $items_to_send ); |
||
| 510 | |||
| 511 | if ( ! $result || is_wp_error( $result ) ) { |
||
| 512 | // error_log("There was an error sending data:"); |
||
| 513 | // error_log(print_r($result, 1)); |
||
| 514 | $result = $this->sync_queue->checkin( $buffer ); |
||
| 515 | |||
| 516 | if ( is_wp_error( $result ) ) { |
||
| 517 | error_log( "Error checking in buffer: " . $result->get_error_message() ); |
||
| 518 | $this->sync_queue->force_checkin(); |
||
| 519 | } |
||
| 520 | // try again in 1 minute |
||
| 521 | $this->schedule_sync( "+1 minute" ); |
||
| 522 | } else { |
||
| 523 | |||
| 524 | // scan the sent data to see if a full sync started or finished |
||
| 525 | if ( $this->buffer_includes_action( $buffer, 'jetpack_full_sync_start' ) ) { |
||
| 526 | $this->full_sync_client->set_status_sending_started(); |
||
| 527 | } |
||
| 528 | |||
| 529 | if ( $this->buffer_includes_action( $buffer, 'jetpack_full_sync_end' ) ) { |
||
| 530 | $this->full_sync_client->set_status_sending_finished(); |
||
| 531 | } |
||
| 532 | |||
| 533 | $this->sync_queue->close( $buffer, $result ); |
||
| 534 | // check if there are any more events in the buffer |
||
| 535 | // if so, schedule a cron job to happen soon |
||
| 536 | if ( $this->sync_queue->has_any_items() ) { |
||
| 537 | $this->schedule_sync( "+1 minute" ); |
||
| 538 | } |
||
| 539 | } |
||
| 540 | } |
||
| 541 | |||
| 542 | private function buffer_includes_action( $buffer, $action_name ) { |
||
| 543 | foreach ( $buffer->get_items() as $item ) { |
||
| 544 | if ( $item[0] === $action_name ) { |
||
| 545 | return true; |
||
| 546 | } |
||
| 547 | } |
||
| 548 | |||
| 549 | return false; |
||
| 550 | } |
||
| 551 | |||
| 552 | function expand_wp_insert_post( $args ) { |
||
| 553 | // list( $post_ID, $post, $update ) = $args; |
||
| 554 | return array( $args[0], $this->filter_post_content_and_add_links( $args[1] ), $args[2] ); |
||
| 555 | } |
||
| 556 | |||
| 557 | // Expands wp_insert_post to include filtered content |
||
| 558 | function filter_post_content_and_add_links( $post ) { |
||
| 569 | |||
| 570 | private function schedule_sync( $when ) { |
||
| 571 | wp_schedule_single_event( strtotime( $when ), 'jetpack_sync_actions' ); |
||
| 572 | } |
||
| 573 | |||
| 574 | function force_sync_constants() { |
||
| 575 | foreach ( $this->constants_whitelist as $name ) { |
||
| 576 | delete_option( self::CONSTANTS_CHECKSUM_OPTION_NAME . "_$name" ); |
||
| 577 | } |
||
| 578 | |||
| 579 | delete_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME ); |
||
| 580 | $this->maybe_sync_constants(); |
||
| 581 | } |
||
| 582 | |||
| 583 | function force_sync_options() { |
||
| 593 | |||
| 594 | function force_sync_network_options() { |
||
| 604 | |||
| 605 | View Code Duplication | private function maybe_sync_constants() { |
|
| 606 | if ( get_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME ) ) { |
||
| 607 | return; |
||
| 608 | } |
||
| 609 | |||
| 610 | $constants = $this->get_all_constants(); |
||
| 611 | if ( empty( $constants ) ) { |
||
| 612 | return; |
||
| 613 | } |
||
| 614 | |||
| 615 | set_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_constants_wait_time ); |
||
| 616 | |||
| 617 | // only send the constants that have changed |
||
| 618 | foreach ( $constants as $name => $value ) { |
||
| 619 | $checksum = $this->get_check_sum( $value ); |
||
| 620 | |||
| 621 | // explicitly not using Identical comparison as get_option returns a string |
||
| 622 | if ( $checksum != get_option( self::CONSTANTS_CHECKSUM_OPTION_NAME . "_$name" ) ) { |
||
| 623 | /** |
||
| 624 | * Tells the client to sync a constant to the server |
||
| 625 | * |
||
| 626 | * @since 4.1 |
||
| 627 | * |
||
| 628 | * @param string The name of the constant |
||
| 629 | * @param mixed The value of the constant |
||
| 630 | */ |
||
| 631 | do_action( 'jetpack_sync_constant', $name, $value ); |
||
| 636 | |||
| 637 | private function get_all_constants() { |
||
| 643 | |||
| 644 | private function get_constant( $constant ) { |
||
| 651 | |||
| 652 | public function force_sync_callables() { |
||
| 660 | |||
| 661 | View Code Duplication | private function maybe_sync_callables() { |
|
| 691 | |||
| 692 | private function get_all_callables() { |
||
| 698 | |||
| 699 | private function get_callable( $callable ) { |
||
| 702 | |||
| 703 | // Is public so that we don't have to store so much data all the options twice. |
||
| 704 | function get_all_options() { |
||
| 712 | |||
| 713 | function get_all_network_options() { |
||
| 721 | |||
| 722 | private function get_check_sum( $values ) { |
||
| 725 | |||
| 726 | View Code Duplication | function jetpack_sync_core_icon() { |
|
| 742 | |||
| 743 | function get_sync_queue() { |
||
| 746 | |||
| 747 | function reset_sync_queue() { |
||
| 750 | |||
| 751 | function set_defaults() { |
||
| 777 | |||
| 778 | function reset_data() { |
||
| 781 | } |
||
| 782 |