static function send_data($data, $codec_name, $sent_timestamp, $queue_id) { Jetpack::load_xml_rpc_client(); $query_args = array('sync' => '1', 'codec' => $codec_name, 'timestamp' => $sent_timestamp, 'queue' => $queue_id, 'home' => get_home_url(), 'siteurl' => get_site_url()); // Has the site opted in to IDC mitigation? if (Jetpack::sync_idc_optin()) { $query_args['idc'] = true; } if (Jetpack_Options::get_option('migrate_for_idc', false)) { $query_args['migrate_for_idc'] = true; } $query_args['timeout'] = Jetpack_Sync_Settings::is_doing_cron() ? 30 : 15; $url = add_query_arg($query_args, Jetpack::xmlrpc_api_url()); $rpc = new Jetpack_IXR_Client(array('url' => $url, 'user_id' => JETPACK_MASTER_USER, 'timeout' => $query_args['timeout'])); $result = $rpc->query('jetpack.syncActions', $data); if (!$result) { return $rpc->get_jetpack_error(); } $response = $rpc->getResponse(); // Check if WordPress.com IDC mitigation blocked the sync request if (is_array($response) && isset($response['error_code'])) { $error_code = $response['error_code']; $allowed_idc_error_codes = array('jetpack_url_mismatch', 'jetpack_home_url_mismatch', 'jetpack_site_url_mismatch'); if (in_array($error_code, $allowed_idc_error_codes)) { Jetpack_Options::update_option('sync_error_idc', Jetpack::get_sync_error_idc_option($response)); } return new WP_Error('sync_error_idc', esc_html__('Sync has been blocked from WordPress.com because it would cause an identity crisis', 'jetpack')); } return $response; }
static function set_doing_cron($is_doing_cron) { // set to NULL to revert to WP_IMPORTING, the standard behaviour self::$is_doing_cron = $is_doing_cron; }
public function maybe_sync_callables() { if (!is_admin() || Jetpack_Sync_Settings::is_doing_cron()) { return; } if (get_transient(self::CALLABLES_AWAIT_TRANSIENT_NAME)) { return; } set_transient(self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime(true), Jetpack_Sync_Defaults::$default_sync_callables_wait_time); $callables = $this->get_all_callables(); if (empty($callables)) { return; } $callable_checksums = (array) get_option(self::CALLABLES_CHECKSUM_OPTION_NAME, array()); // only send the callables that have changed foreach ($callables as $name => $value) { $checksum = $this->get_check_sum($value); // explicitly not using Identical comparison as get_option returns a string if (!$this->still_valid_checksum($callable_checksums, $name, $checksum) && !is_null($value)) { /** * Tells the client to sync a callable (aka function) to the server * * @since 4.2.0 * * @param string The name of the callable * @param mixed The value of the callable */ do_action('jetpack_sync_callable', $name, $value); $callable_checksums[$name] = $checksum; } else { $callable_checksums[$name] = $checksum; } } update_option(self::CALLABLES_CHECKSUM_OPTION_NAME, $callable_checksums); }