Leave a Reply

5 comments

  1. Here is a simple solution. Im hooking into login_headerurl. Maybe there is a better hook for this but it works, Put this in your functions.php:

    function wpse_lost_password_redirect() {
    
        // Check if have submitted 
        $confirm = ( isset($_GET['checkemail'] ) ? $_GET['checkemail'] : '' );
    
        if( $confirm ) {
            wp_redirect( home_url() ); 
            exit;
        }
    }
    add_action('login_headerurl', 'wpse_lost_password_redirect');
    

    What it does, it runs on login_headerurl and checks for the GET parameter “checkedmail” which you get after you submitted a valid username or email. Then i redirect by using the awsome function wp_redirect to the home_url.

    UPDATE after comment

    If you want to redirect the user after submitted a new password you only need to use the hook password_reset here is an example:

    function wpse_lost_password_redirect() {
        wp_redirect( home_url() ); 
        exit;
    }
    add_action('after_password_reset', 'wpse_lost_password_redirect');
    
  2. The “correct” answer doesn’t work here because the action ‘password_reset’ fires before the password is reset.

    I modified the first answer, before the update, to work.

    function wpse_lost_password_redirect() {
    
        // Check if have submitted
        $confirm = ( isset($_GET['action'] ) && $_GET['action'] == resetpass );
    
        if( $confirm ) {
            wp_redirect( home_url() );
            exit;
        }
    }
    add_action('login_headerurl', 'wpse_lost_password_redirect');
    

    Edit: Didn’t have enough rep to comment so I’m posting this as a new answer.

  3. I can’t see how the “UPDATE after comment” answer works.

    The documentation for the ‘password_reset’ hook says “Fires before the user’s password is reset.”.
    If you redirect, then exit the password won’t get changed.

    Since I had a similar need I developed my solution to the problem.
    We still respond to the “password_reset” hook but instead of performing the redirect immediately we add a hook for the “login_url” filter.
    And it’s in this filter that we add the redirections to the home page after the user has logged in.

     add_action( "password_reset", "rngs_password_reset", 10, 2 );
    
    /**
     * Implement "password_reset" for RNGS
     *
     * After a password reset has been performed we want the Log in link to redirect the user to the home url.
     * When we see this action being run we know that we should be filtering "login_url" to add the redirect the home page.
     * We don't filter "login_url" any other time. 
     *
     * @param WP_User $user - the user object
     * @param string $new_pass - the new password
     *  
     */
    function rngs_password_reset( $user, $new_pass ) {
      add_filter( "login_url", "rngs_login_url", 10, 2 );
    }
    
    /**
     *  Implement "login_url" filter for RNGS
     *
     * Redirect the user to the home page after logging in
     *
     * @TODO - make this an option field that controls where the logged in user goes
     * @TODO - dependent upon role?
     * 
     * @param string $login_url - the original login_url which is not expected to include "redirect_to" or "reauth"
     * @param string $redirect - expected to be null/blank
     */
    function rngs_login_url( $login_url, $redirect ) {
      $home_redirect = home_url();
      $login_url = add_query_arg('redirect_to', urlencode( $home_redirect ), $login_url);
      return( $login_url );
    } 
    
  4. Rediret to is a wordpress feature you don’t need to create a plugin for it, just add &redirect_to= the url and it will work.
    Example:

    echo '<a href="'home_url().'/wp-login.php?action=lostpassword&amp;redirect_to='.get_bloginfo('url').'?sli=lost" rel="nofollow" title="Forgot Password">'Forgot Password'</a>';