public static disconnect ( $update_activated_state = true ) |
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();
}
/** * Disconnect Jetpack Blogs or Users * * ## OPTIONS * * blog: Disconnect the entire blog. * * user <user_identifier>: Disconnect a specific user from WordPress.com. * * Please note, the primary account that the blog is connected * to WordPress.com with cannot be disconnected without * disconnecting the entire blog. * * ## EXAMPLES * * wp jetpack disconnect blog * wp jetpack disconnect user 13 * wp jetpack disconnect user username * wp jetpack disconnect user [email protected] * * @synopsis blog|[user <user_id>] */ public function disconnect($args, $assoc_args) { if (!Jetpack::is_active()) { WP_CLI::error(__('You cannot disconnect, without having first connected.', 'jetpack')); } $action = isset($args[0]) ? $args[0] : 'prompt'; if (!in_array($action, array('blog', 'user', 'prompt'))) { WP_CLI::error(sprintf(__('%s is not a valid command.', 'jetpack'), $action)); } if (in_array($action, array('user'))) { if (isset($args[1])) { $user_id = $args[1]; if (ctype_digit($user_id)) { $field = 'id'; $user_id = (int) $user_id; } elseif (is_email($user_id)) { $field = 'email'; $user_id = sanitize_user($user_id, true); } else { $field = 'login'; $user_id = sanitize_user($user_id, true); } if (!($user = get_user_by($field, $user_id))) { WP_CLI::error(__('Please specify a valid user.', 'jetpack')); } } else { WP_CLI::error(__('Please specify a user.', 'jetpack')); } } switch ($action) { case 'blog': Jetpack::log('disconnect'); Jetpack::disconnect(); WP_CLI::success(__('Jetpack has been successfully disconnected.', 'jetpack')); break; case 'user': if (Jetpack::unlink_user($user->ID)) { Jetpack::log('unlink', $user->ID); WP_CLI::success(sprintf(__('%s has been successfully disconnected.', 'jetpack'), $action)); } else { WP_CLI::error(sprintf(__('%s could not be disconnected. Are you sure they\'re connected currently?', 'jetpack'), "{$user->login} <{$user->email}>")); } break; case 'prompt': WP_CLI::error(__('Please specify if you would like to disconnect a blog or user.', 'jetpack')); break; } }