WP_Recovery_Mode_Key_Service
- Since
- 5.2.0
- Source
wp-includes/class-wp-recovery-mode-key-service.php:14
Core class used to generate and validate keys used to enter Recovery Mode.
Compatibility
- WordPress
- since 5.2.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 · 1
Every hook that fires from inside WP_Recovery_Mode_Key_Service, in the order it appears in the class, grouped by the method that fires it.
Properties · 1
$option_namestringprivate- The option name used to store the keys.
Methods · 7
- generate_recovery_mode_token()Creates a recovery mode token.
- generate_and_store_recovery_mode_key()Creates a recovery mode key.
- validate_recovery_mode_key()Verifies if the recovery mode key is correct.
- clean_expired_keys()Removes expired recovery mode keys.
- remove_key()Removes a used recovery key.
- get_keys()Gets the recovery key records.
- update_keys()Updates the recovery key records.
Source code
#[AllowDynamicProperties]final class WP_Recovery_Mode_Key_Service { /** * The option name used to store the keys. * * @since 5.2.0 * @var string */ private $option_name = 'recovery_keys'; /** * Creates a recovery mode token. * * @since 5.2.0 * * @return string A random string to identify its associated key in storage. */ public function generate_recovery_mode_token() { return wp_generate_password( 22, false ); } /** * Creates a recovery mode key. * * @since 5.2.0 * @since 6.8.0 The stored key is now hashed using wp_fast_hash() instead of phpass. * * @param string $token A token generated by {@see WP_Recovery_Mode_Key_Service::generate_recovery_mode_token()}. * @return string Recovery mode key. */ public function generate_and_store_recovery_mode_key( $token ) { $key = wp_generate_password( 22, false ); $records = $this->get_keys(); $records[ $token ] = array( 'hashed_key' => wp_fast_hash( $key ), 'created_at' => time(), ); $this->update_keys( $records ); /** * Fires when a recovery mode key is generated. * * @since 5.2.0 * * @param string $token The recovery data token. * @param string $key The recovery mode key. */ do_action( 'generate_recovery_mode_key', $token, $key ); return $key; } /** * Verifies if the recovery mode key is correct. * * Recovery mode keys can only be used once; the key will be consumed in the process. * * @since 5.2.0 * * @param string $token The token used when generating the given key. * @param string $key The plain text key. * @param int $ttl Time in seconds for the key to be valid for. * @return true|WP_Error True on success, error object on failure. */ public function validate_recovery_mode_key( $token, $key, $ttl ) { $records = $this->get_keys(); if ( ! isset( $records[ $token ] ) ) { return new WP_Error( 'token_not_found', __( 'Recovery Mode not initialized.' ) ); } $record = $records[ $token ]; $this->remove_key( $token ); if ( ! is_array( $record ) || ! isset( $record['hashed_key'], $record['created_at'] ) ) {Changelog
Introduced in 5.2.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-recovery-mode-key-service.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.