0

I have a custom login page and hence have setup the following redirects:

add_action('init', 'my_redirect_login_page');
add_action('wp_login_failed', 'my_custom_login_failed');
add_filter('authenticate', 'my_verify_user_pass', 1, 3);
add_action('wp_logout', 'my_logout_redirect');

function my_redirect_login_page()
{

    $login_page = site_url('/careers/login-register/');
    $page_viewed = basename($_SERVER['REQUEST_URI']);

    if ($page_viewed == 'wp-login.php' && $_SERVER['REQUEST_METHOD'] == 'GET') {
        wp_redirect($login_page);
        exit;
    }

}

function my_custom_login_failed()
{
    $uri = (isset($_POST['type']) and $_POST['type'] == 'admin-login') ? '/admin-login/' : '/careers/login-register/';
    $login_page = site_url($uri);
    wp_redirect($login_page . '?login=failed');
    exit;

}

function my_verify_user_pass($user, $username, $password)
{
    $uri = (isset($_POST['type']) and $_POST['type'] == 'admin-login') ? '/admin-login/' : '/careers/login-register/';
    $login_page = site_url($uri);
    if ($username == '' || $password == '') {
        wp_redirect($login_page . "?login=empty");
        exit;
    }
}

This works well, but I have recently discovered that it also redirects users to /careers/login-register/?login=empty when they request a new password.

I tried to fix this by adding:

add_filter('lostpassword redirect', 'my_lost_password_redirect');

function my_lost_password_redirect()
{
    $login_page = site_url();
    wp_redirect($login_page . '/?checkemail=confirm');
    exit();
}

...but it didn't work.

I tried playing around with the priority parameter on the authenticate filter but it didn't change anything.

Edit:

I actually found out a way to do it, such as:

function my_verify_user_pass($user, $username, $password) {

    $page_viewed = $_SERVER['REQUEST_URI'];

    $redirect = (strpos($page_viewed, '?checkemail=confirm') !== false) ? false : true;

    if ($redirect) {
        $uri = (isset($_POST['type']) and $_POST['type'] == 'admin-login') ? '/admin-login/' : '/careers/login-register/';
        $login_page = site_url($uri);
        if ($username == '' || $password == '') {
            wp_redirect($login_page . "?login=empty");
            exit;
        }
    }

}

However not sure if there is a more standard way of achieving it or a way to not break it in the first place - is this possible?

Any ideas?

0

Do you just want to change the link url for lost password?

function my_lost_password_url() {
    return home_url('/lost-password');
}
add_filter('lostpassword_url', 'my_lost_password_url');
  • No, the lost password URL stays the same, but when they successfully request one they place they are redirected to shouldn't be changed from the default, which is wp-login.php/?checkemail=confirm. Also, please see updated question shortly. – Brett Jan 4 at 15:55

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.