Пример #1
0
 function test_clear_all_idc_options_clears_expected()
 {
     $options = array('sync_error_idc', 'safe_mode_confirmed', 'migrate_for_idc');
     foreach ($options as $option) {
         Jetpack_Options::update_option($option, true);
         $this->assertTrue(Jetpack_Options::get_option($option));
     }
     Jetpack_IDC::clear_all_idc_options();
     foreach ($options as $option) {
         $this->assertFalse(Jetpack_Options::get_option($option));
     }
 }
Пример #2
0
 /**
  * Disconnects from the Jetpack servers.
  * Forgets all connection details and tells the Jetpack servers to do the same.
  * @static
  */
 public static function disconnect($update_activated_state = true)
 {
     wp_clear_scheduled_hook('jetpack_clean_nonces');
     Jetpack::clean_nonces(true);
     // If the site is in an IDC because sync is not allowed,
     // let's make sure to not disconnect the production site.
     if (!self::validate_sync_error_idc_option()) {
         Jetpack::load_xml_rpc_client();
         $xml = new Jetpack_IXR_Client();
         $xml->query('jetpack.deregister');
     }
     Jetpack_Options::delete_option(array('register', 'blog_token', 'user_token', 'user_tokens', 'master_user', 'time_diff', 'fallback_no_verify_ssl_certs'));
     Jetpack_IDC::clear_all_idc_options();
     if ($update_activated_state) {
         Jetpack_Options::update_option('activated', 4);
     }
     if ($jetpack_unique_connection = Jetpack_Options::get_option('unique_connection')) {
         // Check then record unique disconnection if site has never been disconnected previously
         if (-1 == $jetpack_unique_connection['disconnected']) {
             $jetpack_unique_connection['disconnected'] = 1;
         } else {
             if (0 == $jetpack_unique_connection['disconnected']) {
                 //track unique disconnect
                 $jetpack = Jetpack::init();
                 $jetpack->stat('connections', 'unique-disconnect');
                 $jetpack->do_stats('server_side');
             }
             // increment number of times disconnected
             $jetpack_unique_connection['disconnected'] += 1;
         }
         Jetpack_Options::update_option('unique_connection', $jetpack_unique_connection);
     }
     // Delete all the sync related data. Since it could be taking up space.
     require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php';
     Jetpack_Sync_Sender::get_instance()->uninstall();
     // Disable the Heartbeat cron
     Jetpack_Heartbeat::init()->deactivate();
 }
Пример #3
0
 function non_admins_current_screen_check($current_screen)
 {
     self::$current_screen = $current_screen;
     if (isset($current_screen->id) && 'toplevel_page_jetpack' == $current_screen->id) {
         return null;
     }
     // If the user has dismissed the notice, and we're not currently on a Jetpack page,
     // then do not show the non-admin notice.
     if (isset($_COOKIE, $_COOKIE['jetpack_idc_dismiss_notice'])) {
         remove_action('admin_notices', array($this, 'display_non_admin_idc_notice'));
         remove_action('admin_enqueue_scripts', array($this, 'enqueue_idc_notice_files'));
     }
 }
 function authorize($data = array())
 {
     $redirect = isset($data['redirect']) ? esc_url_raw((string) $data['redirect']) : '';
     $jetpack_unique_connection = Jetpack_Options::get_option('unique_connection');
     // Checking if site has been active/connected previously before recording unique connection
     if (!$jetpack_unique_connection) {
         // jetpack_unique_connection option has never been set
         $jetpack_unique_connection = array('connected' => 0, 'disconnected' => 0, 'version' => '3.6.1');
         update_option('jetpack_unique_connection', $jetpack_unique_connection);
         //track unique connection
         $jetpack = $this->get_jetpack();
         $jetpack->stat('connections', 'unique-connection');
         $jetpack->do_stats('server_side');
     }
     // increment number of times connected
     $jetpack_unique_connection['connected'] += 1;
     Jetpack_Options::update_option('unique_connection', $jetpack_unique_connection);
     $role = Jetpack::translate_current_user_to_role();
     if (!$role) {
         return new Jetpack_Error('no_role', 'Invalid request.', 400);
     }
     $cap = Jetpack::translate_role_to_cap($role);
     if (!$cap) {
         return new Jetpack_Error('no_cap', 'Invalid request.', 400);
     }
     if (!empty($data['error'])) {
         return new Jetpack_Error($data['error'], 'Error included in the request.', 400);
     }
     if (!isset($data['state'])) {
         return new Jetpack_Error('no_state', 'Request must include state.', 400);
     }
     if (!ctype_digit($data['state'])) {
         return new Jetpack_Error($data['error'], 'State must be an integer.', 400);
     }
     $current_user_id = get_current_user_id();
     if ($current_user_id != $data['state']) {
         return new Jetpack_Error('wrong_state', 'State does not match current user.', 400);
     }
     if (empty($data['code'])) {
         return new Jetpack_Error('no_code', 'Request must include an authorization code.', 400);
     }
     $token = $this->get_token($data);
     if (is_wp_error($token)) {
         $code = $token->get_error_code();
         if (empty($code)) {
             $code = 'invalid_token';
         }
         return new Jetpack_Error($code, $token->get_error_message(), 400);
     }
     if (!$token) {
         return new Jetpack_Error('no_token', 'Error generating token.', 400);
     }
     $is_master_user = !Jetpack::is_active();
     Jetpack::update_user_token($current_user_id, sprintf('%s.%d', $token, $current_user_id), $is_master_user);
     if (!$is_master_user) {
         Jetpack::state('message', 'linked');
         // Don't activate anything since we are just connecting a user.
         return 'linked';
     }
     $redirect_on_activation_error = 'client' === $data['auth_type'] ? true : false;
     if ($active_modules = Jetpack_Options::get_option('active_modules')) {
         Jetpack::delete_active_modules();
         Jetpack::activate_default_modules(999, 1, $active_modules, $redirect_on_activation_error);
     } else {
         Jetpack::activate_default_modules(false, false, array(), $redirect_on_activation_error);
     }
     // Since this is a fresh connection, be sure to clear out IDC options
     Jetpack_IDC::clear_all_idc_options();
     // Start nonce cleaner
     wp_clear_scheduled_hook('jetpack_clean_nonces');
     wp_schedule_event(time(), 'hourly', 'jetpack_clean_nonces');
     Jetpack::state('message', 'authorized');
     return 'authorized';
 }