Creating a login button for my multisite users

Hello,

I'd like to add a LOGIN link/button to my website http://www.mychampbuilder.com so my registered blog users can sign into their account without having remember the url http://www.theirdomain.com/wp-login.php.

Is there a way to code this or a plugin to use?

Thanks, Chris

  • Webmaster

    People don't need a special URL; you can easily accomplish what you want by simply using the URL you presented above. If they are a member of only one site (theirs), then WordPress will tell them with a message like this:

    You attempted to access the "myChampBuilder" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "myChampBuilder" dashboard, please contact your network administrator.

    If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.

    Your Sites
    Your site name Visit Dashboard | View Site

    If they will be a user on your main site too, then you have a whole new problem: setting their "primary site" to which ever dashboard they will be most often be accessing.

  • Jack Kitterhing

    Hi there Chris,

    Hope you're well today and thanks for your question.

    You could use a small piece of code such as

    <?php echo wp_login_url( $redirect ); ?>
    <a href="<?php echo wp_login_url( home_url() ); ?>" title="Login">Login</a>

    But as it's php, you'd need to add that in a page template file directly, or install one of the plugins that allow you to execute php in a normal WordPress page.

    Thank you!

    Kind Regards
    Jack.

  • Webmaster

    Jack,

    Was just trying to understand how that code knows the user's mapped domain name.

    According to the question, the user would be on the main site and a link is wanted to allow users to log into their own domain name (presumably a domain name that was mapped to a sub-domain of the main site). How does your code send them to the requested URL, which was http://www.theirdomain.com/wp-login.php.

    Also, does the user's primary site not come into play here? I mean, from the main site home page the website has no idea which user it may be dealing with or what their site name may be, right?

  • Jack Kitterhing

    Hi there Chris and @Webmaster,

    Hope you're both well today.

    My bad here, I completely mis-read the original question, at first I thought

    <a href="<?php bloginfo('url'); ?>/wp-login.php?redirect_to=<?php bloginfo('url'); ?>">log in</a>

    might work, but after testing and re-reading that won't work either, as we don't actually know who the user is or which blog to redirect them to login.

    It could perhaps be done using cookies that are set on signup, but when the user clears them, it again wouldn't work.

    How about if we redirect the user once they have logged in via the main site?

    Something like

    add_filter('login_redirect', 'custom_redirect_filter', 0, 3);
    
    function custom_redirect_filter($redirect_to, $request, $user) {
    $user_blogs = get_blogs_of_user($user->ID);
    foreach ($user_blogs as $user_blog) {
    $user_blog->path;
    return site_url($user_blog->path);
    }
    return site_url();
    }

    Which redirects the user to their blog upon login. :slight_smile:

    Thanks!

    Kind Regards
    Jack.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.