Example #1
0
 /**
  * @depends test_session_write_read
  */
 public function test_session_destroy($session)
 {
     $session->destroy();
     $session = \Pantheon_Sessions\Session::get_by_sid(session_id());
     $this->assertFalse($session);
     $this->assertEmpty($_SESSION);
 }
 /**
  * Delete one or more sessions.
  *
  * [<session-id>...]
  * : One or more session IDs
  *
  * [--all]
  * : Delete all sessions.
  *
  * @subcommand delete
  */
 public function delete($args, $assoc_args)
 {
     global $wpdb;
     if (!PANTHEON_SESSIONS_ENABLED) {
         WP_CLI::error("Pantheon Sessions is currently disabled.");
     }
     if (isset($assoc_args['all'])) {
         $args = $wpdb->get_col("SELECT session_id FROM {$wpdb->pantheon_sessions}");
         if (empty($args)) {
             WP_CLI::warning("No sessions to delete.");
         }
     }
     foreach ($args as $session_id) {
         $session = \Pantheon_Sessions\Session::get_by_sid($session_id);
         if ($session) {
             $session->destroy();
             WP_CLI::log(sprintf("Session destroyed: %s", $session_id));
         } else {
             WP_CLI::warning(sprintf("Session doesn't exist: %s", $session_id));
         }
     }
 }
Example #3
0
/**
 * Session handler assigned by session_set_save_handler().
 *
 * Cleans up a specific session.
 *
 * @param $sid Session ID.
 */
function _pantheon_session_destroy($sid)
{
    $session = \Pantheon_Sessions\Session::get_by_sid($sid);
    if (!$session) {
        return;
    }
    $session->destroy();
}