storage = $storage; } public function start() { if ( $this->storage->exists() ) { $this->storage->refresh(); } else { $this->storage->add_session(); } $session = $this->storage->get_session(); $this->id = $this->storage->get_session_id(); $this->expiry_date = $session['expiry_date']; } /** * @return string */ public function get_id() { return $this->id; } /** * @return DateTime */ public function get_expiry_date() { return $this->expiry_date; } /** * @param string $key * * @return bool */ public function exists( $key ) { return $this->storage->variable_exists( $key ); } /** * @param string $key * * @return string|null */ public function get( $key ) { return $this->storage->get_variable( $key ); } /** * @param string $key * @param string $value */ public function set( $key, $value ) { if ( $this->storage->variable_exists( $key ) ) { $this->storage->update_variable( $key, $value ); } else { $this->storage->add_variable( $key, $value ); } } /** * @param string $key */ public function delete( $key ) { $this->storage->delete_variable( $key ); } public function regenerate() { $this->destroy(); $this->start(); } public function destroy() { $this->storage->delete_session(); $this->id = null; $this->expiry_date = null; } /** * @param int $user_id */ public function log_out_on_other_devices( $user_id ) { if ( class_exists( 'WP_User_Meta_Session_Tokens' ) ) { $session_tokens = WP_User_Meta_Session_Tokens::get_instance( $user_id ); $session_token = wp_get_session_token(); $session_tokens->destroy_others( $session_token ); } } }