WP_Session_Tokens
- Since
- 4.0.0
- Source
wp-includes/class-wp-session-tokens.php:15
Abstract class for managing user session tokens.
Compatibility
- WordPress
- since 4.0.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 3
Every hook that fires from inside WP_Session_Tokens, in the order it appears in the class, grouped by the method that fires it.
Properties · 1
$user_idintprotected- User ID.
Methods · 19
- __construct()Protected constructor. Use the `get_instance()` method to get the instance.
- get_instance()Retrieves a session manager instance for a user.
- hash_token()Hashes the given session token for storage.
- get()Retrieves a user's session for the given token.
- verify()Validates the given session token for authenticity and validity.
- create()Generates a session token and attaches session information to it.
- update()Updates the data for the session with the given token.
- destroy()Destroys the session with the given token.
- destroy_others()Destroys all sessions for this user except the one with the given token (presumably the one in use).
- is_still_valid()Determines whether a session is still valid, based on its expiration timestamp.
- destroy_all()Destroys all sessions for a user.
- destroy_all_for_all_users()Destroys all sessions for all users.
- get_all()Retrieves all sessions for a user.
- get_sessions()Retrieves all sessions of the user.
- get_session()Retrieves a session based on its verifier (token hash).
- update_session()Updates a session based on its verifier (token hash).
- destroy_other_sessions()Destroys all sessions for this user, except the single session with the given verifier.
- destroy_all_sessions()Destroys all sessions for the user.
- drop_sessions()Destroys all sessions for all users.
Source code
#[AllowDynamicProperties]abstract class WP_Session_Tokens { /** * User ID. * * @since 4.0.0 * @var int User ID. */ protected $user_id; /** * Protected constructor. Use the `get_instance()` method to get the instance. * * @since 4.0.0 * * @param int $user_id User whose session to manage. */ protected function __construct( $user_id ) { $this->user_id = $user_id; } /** * Retrieves a session manager instance for a user. * * This method contains a {@see 'session_token_manager'} filter, allowing a plugin to swap out * the session manager for a subclass of `WP_Session_Tokens`. * * @since 4.0.0 * * @param int $user_id User whose session to manage. * @return WP_Session_Tokens The session object, which is by default an instance of * the `WP_User_Meta_Session_Tokens` class. */ final public static function get_instance( $user_id ) { /** * Filters the class name for the session token manager. * * @since 4.0.0 * * @param string $session Name of class to use as the manager. * Default 'WP_User_Meta_Session_Tokens'. */ $manager = apply_filters( 'session_token_manager', 'WP_User_Meta_Session_Tokens' ); return new $manager( $user_id ); } /** * Hashes the given session token for storage. * * @since 4.0.0 * * @param string $token Session token to hash. * @return string A hash of the session token (a verifier). */ private function hash_token( $token ) { return hash( 'sha256', $token ); } /** * Retrieves a user's session for the given token. * * @since 4.0.0 * * @param string $token Session token. * @return array|null The session, or null if it does not exist. */ final public function get( $token ) { $verifier = $this->hash_token( $token ); return $this->get_session( $verifier ); } /** * Validates the given session token for authenticity and validity. * * Checks that the given token is present and hasn't expired. * * @since 4.0.0 * * @param string $token Token to verify.Changelog
Introduced in 4.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-session-tokens.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.