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 * * @global PasswordHash $wp_hasher Portable PHP password hashing framework instance. * * @param string $token A token generated by {@see generate_recovery_mode_token()}. * @return string Recovery mode key. */ public function generate_and_store_recovery_mode_key( $token ) { global $wp_hasher; $key = wp_generate_password( 22, false ); if ( empty( $wp_hasher ) ) { require_once ABSPATH . WPINC . '/class-phpass.php'; $wp_hasher = new PasswordHash( 8, true ); } $hashed = $wp_hasher->HashPassword( $key ); $records = $this->get_keys(); $records[ $token ] = array( 'hashed_key' => $hashed, '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 * * @global PasswordHash $wp_hasher Portable PHP password hashing framework instance. * * @param string $token The token used when generating the given key. * @param string $key The unhashed 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.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 6.7.7 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.