1

We have a situation where the users (children) keep not forgetting their password but making trivial mistakes while trying to login.
As per question they should be first redirected to page e.g. id=5 with instructions like:

Please go back and:
Activate your cookies
Check if the correct language is on your keyboard
Ask your mother to log you in
etc...
If none of the above works please click here (http://oursite.com/wp-login.php?action=lostpassword) to ask for a new password

So, the lostpassword link on the login page should redirect to the existing page with the custom message/instructions and then, the link on the page to the actual lostpassword link.

PS: I believe that the lately introduced lostpassword_post hook could be useful.

1

This is straightforward.

  1. Hook on init to detect the lostpassword page

  2. If the user is not coming from your instructions page (which we defined by adding extra query parameter) he'll be redirected to your custom page

  3. In your custom page add the link to lost password page including the extra parameter we set to skip the redirection.

    add_action( 'init', 'lostpassword_instructions' );
    
    function lostpassword_instructions() {
    
    
        global $pagenow;
    
        if ( $pagenow == 'wp-login.php' && 
            isset( $_REQUEST[ 'action' ] ) && 
            $_REQUEST[ 'action' ] == 'lostpassword' && 
            ! isset( $_REQUEST[ 'skip' ] )
        ) {
    
            exit( wp_redirect( 'http://domain.com/lost-password-instructions' ) );
    
        }
    
    }
    

Now on your custom page, something like that should work:

$url = 'http://domain.com/wp-login.php?action=lostpassword&skip=true';
  • A clarification please. Where should $url = wp_lostpassword_url() . '&skip=true'; be placed? I tested your un-edited answer and http://domain.com/wp-login.php?action=lostpassword&skip=true works just fine. Why the change? – marikamitsos Sep 28 '16 at 20:26
  • very sorry. i just meant to say that in order to send user finally (after seeing the instructions) you have to send them to the password reset url but with skip=true at the end of url. let me know if that worked – Ahmed Fouad Sep 28 '16 at 20:59
  • As mentioned: adding http://domain.com/wp-login.php?action=lostpassword&skip=true works great. I have also upvoted your answer. An upvoted question draws more attention and an upvoted answer reassures for a working solution. Thanks again – marikamitsos Sep 28 '16 at 21:08
0

the action login_form_lostpassword is called before the lost password page. try this :

add_action("login_form_lostpassword", function () {

    echo "on the lostpassword page";
    exit();

});

instead of the echo, redirect to your instructions page

  • Thank you for the quick reply. I have not tested your solution yet. Still I wonder. Will the same link (lostpassword) on the page point to the default lostpassword screen? – marikamitsos Sep 28 '16 at 20:01
  • I finally got to test your code (add_action("login_form_lostpassword", function () { echo "mydomain.com/lostpass.php"; exit(); });)and all it does it give mydomain.com/lostpass.php on the mydomain.com/wp-login.php?action=lostpassword. Could you please clarify exactly where and how to use it? – marikamitsos Nov 8 '16 at 19:33

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.