init() public static method

Singleton
Since: 2.3.3
public static init ( ) : Jetpack_Heartbeat
return Jetpack_Heartbeat
 /**
  * @covers Jetpack_Heartbeat::cron_exec
  * @since 3.9.0
  */
 public function test_cron_exec()
 {
     $this->heartbeat_action = false;
     add_action('jetpack_heartbeat', array($this, 'jetpack_heartbeat'));
     Jetpack_Heartbeat::init()->cron_exec();
     $this->assertTrue($this->heartbeat_action);
 }
 public function test_sends_stats_data_on_heartbeat_on_multisite()
 {
     global $wpdb;
     if (!is_multisite()) {
         $this->markTestSkipped('Run it in multi site mode');
     }
     $user_id = $this->factory->user->create();
     $mu_blog_user_id = $this->factory->user->create();
     // create a different blog
     $suppress = $wpdb->suppress_errors();
     $other_blog_id = wpmu_create_blog('foo.com', '', "My Blog", $user_id);
     $wpdb->suppress_errors($suppress);
     // create a user from within that blog (won't be synced)
     switch_to_blog($other_blog_id);
     add_user_to_blog($other_blog_id, $mu_blog_user_id, 'administrator');
     $heartbeat = Jetpack_Heartbeat::init();
     $heartbeat->cron_exec();
     $this->sender->do_sync();
     $action = $this->server_event_storage->get_most_recent_event('jetpack_sync_heartbeat_stats');
     restore_current_blog();
     $this->assertEquals(JETPACK__VERSION, $action->args[0]['version']);
     $this->assertFalse(isset($action->args[0]['users']));
 }
Esempio n. 3
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);
     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'));
     if ($update_activated_state) {
         Jetpack_Options::update_option('activated', 4);
     }
     // Disable the Heartbeat cron
     Jetpack_Heartbeat::init()->deactivate();
 }
 /**
  * Removes all connection options
  * @static
  */
 public static function plugin_deactivation()
 {
     Jetpack::disconnect(false);
     Jetpack_Heartbeat::init()->deactivate();
 }
 /**
  * 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);
     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'));
     if ($update_activated_state) {
         Jetpack_Options::update_option('activated', 4);
     }
     $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);
     // Disable the Heartbeat cron
     Jetpack_Heartbeat::init()->deactivate();
 }
Esempio n. 6
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();
 }