WP_Recovery_Mode_Key_Service::generate_and_store_recovery_mode_key() WordPress Method

The WP_Recovery_Mode_Key_Service::generate_and_store_recovery_mode_key() method is used to generate and store a recovery mode key for a Wordpress site. This key can be used to access the site if the administrator password is lost or forgotten.

WP_Recovery_Mode_Key_Service::generate_and_store_recovery_mode_key( string $token ) #

Creates a recovery mode key.


Parameters

$token

(string)(Required)A token generated by generate_recovery_mode_token().


Top ↑

Return

(string) Recovery mode key.


Top ↑

Source

File: wp-includes/class-wp-recovery-mode-key-service.php

	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;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.