Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to able to redirect to get_bloginfo('url'); after reseting password.

But I cannot for life of me find any simple answer or function to do this.

Does anyone know if this is possible?

Thank Josh

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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('password_reset', 'wpse_lost_password_redirect');
share|improve this answer
    
Hi Pontus, thank you very much for your answer, this will come use for another time i'm sure. But I'm in fact after the re-direct after the new passord itself has been reset, not after the email/user submission. See this screenshot of form that I need it the redirect to work on... i.imgur.com/x2IUQ0c.jpg - Thanks –  Joshc Jan 26 '13 at 15:39
    
Aaah i see, thats actually easier than the function before. See my updated answer. –  Pontus Abrahamsson Jan 26 '13 at 18:51
    
Awgh dude, these are both awesome!! Thanks for sharing with us, it worked at treat! Nice one. –  Joshc Jan 27 '13 at 12:32
    
I just used your first answer for something else, told you it would come in handy. Thank you again. –  Joshc Feb 14 '13 at 18:28
    
Hehe, you are welcome! –  Pontus Abrahamsson Feb 14 '13 at 18:31

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 );
} 
share|improve this answer

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.

share|improve this answer
    
This should be posted as an answer. Good job. –  Christine Cooper Nov 4 at 15:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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