Intercept invalid email during lost_password

Invalid email screen

On the website I’m developing, I need all login-related forms to be on custom, branded pages. I have pretty much covered them all, but I have just one case I can’t manage correctly.

I have set a custom page for the Lost password? page, by adding the filter below, then creating a new page with a custom template that renders the Insert email to get the link form.

function custom_lost_password_page( $lostpassword_url, $redirect ) {
    return home_url( '/lost-password/' );
}
add_filter( 'lostpassword_url', 'custom_lost_password_page', 10, 2 );

On the page template I set a custom redirect_to input field so that the successful request redirects to my custom login page with a specific message.

<input type="hidden" name="redirect_to" value="<?= site_url('/login?resetlink=sent') ?>">

So far so good. What I can’t seem to intercept, is when the user enter a non-existent email. In that case, no matter what, I get redirected to /wp-login.php?action=lostpassword, which is a native WP page we don’t want, with the corresponding error message.

I can’t seem to find an action or filter to latch onto in this particular case. Google unfortunately wasn’t of help and all similar questions here don’t seem to handle this very specific case.

Any ideas?
Thanks in advance and have a nice day!

Read more here:: Intercept invalid email during lost_password

Leave a Reply

Your email address will not be published. Required fields are marked *