2

I've been struggling searching through a bunch of tutorials with no luck. I have a custom login page and am just replacing the login form with the forgot password form on click. My issue is how to get the form to send the user a reset password link if the correct username or email is entered and return an error if not. I'm trying to do this from a plugin I'm making to handle the login. Here's my simple form. How do I make this work?

  <form id="wp_pass_reset" action="" method="post">
    <input type="text" id="email-field" name="user_input" value="Username or Email" /><br />
    <input type="submit" id="submitbtn" name="submit" value="Reset" />
  </form>
7
  • So anyone could reset anyone's password? Commented Sep 4, 2012 at 23:49
  • lol doh Im gonna edit this Commented Sep 5, 2012 at 0:04
  • This is right article for you. - kvcodes.com/2016/10/wordpress-custom-forgot-password-page
    – Kvvaradha
    Commented Nov 3, 2016 at 4:32
  • I using olympus theme on wordpress. the lost password url redirecrecting to homapage url. here is the code that used for reset password section: php <?php $lostpswd = apply_filters( 'yz_lostpassword_url', wp_lostpassword_url() ); ?> <a href="<?php echo esc_url( $lostpswd ); ?>" class="forgot"> <?php esc_html_e( 'Forgot my Password', 'crum-ext-sign-form' ); ?> </a> what I should to do?
    – zahra
    Commented Oct 27, 2020 at 12:46
  • First you'll need to workout whether wp_lostpassword_url() is returning the wrong URL, or whether it's the yz_lostpassword_url filter that's returning the wrong URL. e.g. just set $lostpswd = wp_lostpassword_url(); and see what happens?
    – Rup
    Commented Oct 27, 2020 at 13:13

1 Answer 1

1

In your plugin you would first set the redirect URL either to nothing: $redirect=''; or the fully qualified URL of the page you want your user to land on after successfully changing their password. For http://example.com/mypage/ you would use: $redirect=site_url( '/mypage/ ' );

Then your form would be:

<form name="lostpasswordform" id="lostpasswordform" action="<?php echo wp_lostpassword_url(); ?>" method="post">
    <p>
        <label>Username or E-mail:<br>
        <input type="text" name="user_login" id="user_login" class="input" value="" size="20" tabindex="10"></label>
    </p>
    <input type="hidden" name="redirect_to" value="<?php echo $redirect ?>">
    <p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button-primary" value="Get New Password" tabindex="100"></p>
</form>

Note: This code is untested. Let me know what happens in the comments if something doesn't work.

Update

As noted in the comments, if you have a filter on login_url wp_lostpassword_url() will point to your custom page. To temporarily restore the default login_url, remove the filter right before the form code:

remove_filter( 'login_url', 'your_filter_function' );

and add it back right after the form code:

add_filter( 'login_url', 'your_filter_function' );
3
  • Is this sending a link with a unique key to the email entered if it's a valid email address of a user? I'm trying to replicate the default method wordpress uses only the link they get sent is pointed to my reset password template and not wordpress's. Commented Sep 6, 2012 at 22:12
  • Have you filtered the login_url to point to your reset template? If so, you'll have to capture the original login_url value in your filter so you can use it instead of the call to wp_lostpassword_url()
    – marfarma
    Commented Sep 6, 2012 at 22:16
  • or alternately remove your filter before the form code, and restore it afterwards. Probably easier that way.
    – marfarma
    Commented Sep 6, 2012 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.