• girl_number_5

    (@trutherone)


    Hello,
    I am using this custom function to prevent wordpress login dialog opening after our own login screen (creating a double login situation)

    add_action(‘init’,’custom_login’);

    function custom_login(){
     global $pagenow;
     if( 'wp-login.php' == $pagenow && $_GET['action']!="logout") {
      wp_redirect('https://www.oursite.com/account/');
      exit();
     }
    }

    This is working great but we can no longer get to our backend as admins via the url:
    https://www.oursite.com/wp-admin/

    Has anyone ideas how io can achieve this and still use our custom login page whch is provided with a plugin in the theme

Viewing 5 replies - 1 through 5 (of 5 total)
  • corebreaker

    (@corebreaker)

    Why don’t you check if an user is already logged in?

    Thread Starter girl_number_5

    (@trutherone)

    hi @corebreaker,
    Not sure what you mean? as an alteration to my existing code?? How would this help us to get to our admin via : https://www.oursite.com/wp-admin/

    corebreaker

    (@corebreaker)

    You know, I’ve just tried you code and it works fine. Let check what should it do.

    You have your own account page, where user can log himself in, or log out, or he just see his account page if he’s already logged in. Or, probably, he can register there.

    But you’re disappointed, that user can go on wp-login.php and get nasty standard WP form of signing up even when he is logged in. In this case you redirect him on account page, unless there’s no act of logging out. And it works.

    But when you’re on the site as an admin you can’t get to admin side through wp-admin, right? But it works in my test site.

    Thread Starter girl_number_5

    (@trutherone)

    Ok almost,
    Basically we have a template which allows us to replace the standard WP login form so members can login and not see the basic WP login – that’s what my script does. But in using this script we admins cannot go to the admin backend via the url :
    https://www.oursite.com/wp-admin/

    This is what i need to do everything else works as expected …

    Moderator bcworkz

    (@bcworkz)

    I think your redirect conditions are too restrictive. It’s stopping the normal login redirects from working. Some other actions besides logout should be allowed to go through to wp-login.php. Figure out which actions do not generate output, they would be safe to not redirect.

    What might be easier would be to simply add ! is_admin() to the conditions for redirect. Just a hunch, I’m not sure if it would help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘prevent double WP login’ is closed to new replies.