Created
June 9, 2018 11:35
-
-
Save GoranGozo/3f36da16e4ad757d0a26aab9de247ffc to your computer and use it in GitHub Desktop.
Reset password link local WordPress
This file contains hidden or 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 | |
/* | |
* I had a local WordPress dev enviroment that for some reason didn't allow me login even though I wrote the correct username and password. | |
* Resetting the password directly in the database didn't work and sending an email to reset the password obviously didn't work locally. | |
* Following the procedure for "I've forgotten my password" generates the neccesserary user_activation_key in the database. | |
* However you still need the correct link/URL on the local WordPress installation to be able to reset the password. | |
* This code generates that link. The code can be added in the index.php in the active theme. | |
* | |
* Based on: https://wordpress.stackexchange.com/questions/239095/how-do-i-create-a-password-reset-link | |
*/ | |
$user_id = 1; | |
global $gw_activate_template; | |
extract( $gw_activate_template->result ); | |
$url = is_multisite() ? get_blogaddress_by_id( (int) $blog_id ) : home_url('', 'http'); | |
$user = new WP_User( (int) $user_id ); | |
$adt_rp_key = get_password_reset_key( $user ); | |
$user_login = $user->user_login; | |
$rp_link = '<a href="' . network_site_url("wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode($user_login), 'login') . '">' . network_site_url("wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode($user_login), 'login') . '</a>'; | |
if ( is_wp_error( $key ) ) { | |
return $key; | |
} | |
?> | |
<h2><?php _e('Your account is now active!'); ?></h2> | |
<div id="signup-welcome"> | |
<p><span class="h3"><?php _e('Username:'); ?></span> <?php echo $user->user_login ?></p> | |
<p>To set your password, select the following link: <?php echo $rp_link; ?></p> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment