I have this manually created page:
$user_login = sanitize_text_field( $_GET['user_login'] );
if ( username_exists( $user_login ) || email_exists($user_login) ) { ?>
<!--Everything has been validated, proceed ....-->
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
function submit()
{
var f = document.getElementById('lostpasswordform');
f.onclick = function () { };
document.lostpasswordform.submit();
}
</script>
</head>
<body onload="submit()">
<form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post">
<input type="hidden" name="user_login" id="user_login" class="input" value="<?php echo ($user_login); ?>" />
<?php do_action('lost_password'); ?>
</form>
</body>
</html>
<?php
echo "SUCCESS";
exit();
} else {
echo "Entered Username or Email was incorrect, please try again!";
}
Everything seems right, but it doesn’t work when called from an app. If I manually visit domain.example/forgot-password?user_login=username
it does send the reset pass email fine.
So if you want to send the reset password link and you have access to the code base, you can use the following snippet and you can modify it further. Actually this code is a slightly modified version of
wp-login.php
Previous answer didn’t worked for me (says that code is invalid, on wp login page), probably because answer is 1,5 yr old, and something is changed in WP code, so I have updated this code a bit (also from wp-login.php), here it is:
None of the above answer worked for me so I looked into wp-login.php for their default reset functionality. They used get_password_reset_key( $userData ) function . In case someone stuck up on above answers here’s my solution :-
I noticed that after upgrading WordPress to Version 4.3 that the above no longer worked for my custom plugin. It would always report that the key was invalid.
Change:
to
This fixed the issue for me, hope it helps someone else
WordPress 4.3.1
Combined Example ( Tested in 5.2 )
Frontend Form
Js to handle the AJAX submit
Server side to generate the reset link and trigger the e-mail
To show your own custom reset password form
Since the above solution was not working for me I did a minor changes in the bhavesh vala’s code.
Replace :
With this :
And you don’t need to use the update query, so remove the below query :
Happy coding!!!
Try this
instead of
It worked me (wordpress 4.3.1)