wppaste
WordPress

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

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.