Created
May 10, 2019 15:46
-
-
Save derak-kilgo/8b87060698e9f97b1c1aa88073c81619 to your computer and use it in GitHub Desktop.
An example creating an activation link which allows you to set your own password.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Bootstrap this outside of normal wordpress plugin | |
* won't load theme support functionality | |
*/ | |
define( 'WP_USE_THEMES', false ); | |
require( './wp-load.php' ); | |
/* | |
* Need to know the ID for your user. | |
* #1 is usually an admin. Don't put this on a live site. | |
*/ | |
$id = 1; | |
/* | |
* Creates a WP_User object. It needs the user id. | |
*/ | |
$user = new WP_User($id); | |
/* | |
* These are the args we'll need to create a password reset url. | |
*/ | |
$options = array( | |
//reset password action | |
'action'=>'rp', | |
//generate a new key just for this user | |
'key'=>get_password_reset_key($user), | |
//The user "login" name | |
'login'=>$user->user_login | |
); | |
//Our completed password "reset" url. http_build_query turns our array into a url-encoded name/value pairs. | |
$url = get_site_url() . '/wp-login.php?' . http_build_query($options); | |
echo "Password reset link for user $id is <a href='$url'>$url</a>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment