How to Reset a WordPress User Password hosted on Localhost

While working on a WordPress site hosted on a developmental server (simply called, localhost) in my computer, I mistakenly updated my admin password to a random WordPress generated one. Thus, I was logged out and no longer was able to log in again because I have no record of the new password.

Using the password reset option won’t work because email can’t be sent on a local server (at least in mine).

In this concise tutorial, I will show us how to intercept and read the password reset mail meant to be delivered to your account email address. After which, you can copy the URL to reset / change your password.

Paste the code below to an site specific activated plugin or any plugin file that is currently active.


add_filter( 'retrieve_password_message', 'w3guy_password_reset_mail_content', 10, 2 );
function w3guy_password_reset_mail_content( $message, $key ) {
	var_dump( $message );
	exit;
}

On clicking the submit button to reset your password, you will see the password reset message displayed with the following text where http://localhost.dev is the URL of my locally hosted WordPress.

Someone requested that the password be reset for the following account:

http://localhost.dev/

Username: collizo4sky

If this was a mistake, just ignore this email and nothing will happen.

To reset your password, visit the following address:

Be sure to remove the code after resetting your password.

I just hope someone find this useful someday 😀

Don’t miss out!
Subscribe to My Newsletter
Invalid email address