get_password_reset_key()
Creates a key in the database for password recovery for the specified user and returns this key.
The created key is saved in the wp_users table in the user_activation_key field. Before saving, the key is hashed using the PasswordHash() class and a timestamp of its creation is added: 1523344279:$P$B1WitfrdGBKDfc8G3ESq.shs5ljDno.
This key is used by the WordPress core in the standard password recovery link that is sent to the user's email.
Example code for creating such a link:
network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) // will get // http://example.com/wp-login.php?action=rp&login=login&key=DNNipiJcP3IcasDtPqIQ
The key is created using the function wp_generate_password().
To check if the key is valid, use the function check_password_reset_key().
Hooks from the function
Returns
String|WP_Error.
- Key for password reset.
- WP_Error when the user is not allowed to create a key or when the key could not be written to the database.
Usage
get_password_reset_key( $user );
- $user(WP_User) (required)
- User object for which to create the key.
Examples
#1 Create a key to restore the password
$user = get_userdata( 1 ); echo get_password_reset_key( $user ); // ZedUm9FEt48Kp4aGb5i8
Changelog
| Since 4.4.0 | Introduced. |