5

I know that password_reset hooks:

Runs after the user submits a new password during password reset 
but before the new password is actually set. 

but there is a similar hook AFTER the new password is actually set?

EDIT: It would be logical to use profile_update but I tried, and profile_update seems not get called in case of password change for a 'lost password' procedure, for example. My real problem is auto login after password reset, and the only solution found till now, was using password_reset hook calling manually a wp_set_password before executing my code, so to be sure that password gets changed and THEN my code gets executed. This is not a clean procedure, and I am wondering if there is a solution that is less 'hacky'... I searched a lot, looking at every action hook in wordpress doc, but i can't find a proper solution.

9

I wonder if you're looking for this one:

 /**
  * Fires after the user's password is reset.
  *
  * @since 4.4.0
  *
  * @param object $user     The user.
  * @param string $new_pass New user password.
  */
  do_action( 'after_password_reset', $user, $new_pass );

It was introduced in WordPress 4.4 and lives within the reset_password() function. The after_password_reset hook fires after the wp_set_password().

Update

Here's an untested pre 4.4 workaround idea:

/**
 * Support for the 'after_password_reset' hook in WordPress pre 4.4
 */
add_action( 'password_reset', function( $user, $new_pass )
{
    add_filter( 'pre_option_admin_email', 
        function( $pre_option, $option ) use ( $user, $new_pass )
        {
            // Setup our 'after_password_reset' hook
            if( ! did_action(  'after_password_reset' ) )
                do_action( 'after_password_reset', $user, $new_pass );

            return $pre_option;  
        }  10, 2 );    
}, 10, 2 );

where you should now have your own custom after_password_reset hook.

Remember to backup database before testing.

  • Ah!! They noticed that, at the end! Unfortunately, i have 4.3.1 and I am not sure updating is a good idea at this point. Thank you so much! – Sasha Grievus Feb 19 '16 at 16:05
  • Hopefully you can upgrade to the latest version soon, that's always highly recommended. In the meanwhile I updated the answer with an untested idea. @SashaGrievus – birgire Feb 19 '16 at 17:10
  • I hope to! Only, i have to wait a bit for it contains a lot of custom code and must be tested. :) Thank you for the idea. I'm going to test it asap! – Sasha Grievus Feb 19 '16 at 19:42
2

It seems that you have to use profile_update hook.

There is a similar question here, and here.

So this post might actually be considered duplicate.

  • That is what it would be logical but tried, and profile_update seems not get called in case of password change for a 'lost password' procedure, for example. – Sasha Grievus Feb 19 '16 at 14:04
  • 1
    Then I'm not sure. You can see the code for password reset here: adambrown.info/p/wp_hooks/hook/… – Steven Feb 19 '16 at 14:09
  • wow! this is good! I was worried about missing something that would be done after password_reset, and that's it! Thank you very much! – Sasha Grievus Feb 19 '16 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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