Help with multisite log on to childsite

Hi all,

So I have a WP Multisite setup. And on my main page, I have a link to the wp-login screen. After a user logs in, they get redirected to the childsite that they are registered to.

However, if they go back to my main site, they don't have a way to get back to their childsite. Is there a line of code or something that I can insert to link them to their own childsite, whichever child multisite that would be?

Example:
http://www.example.com <- Main site
http://www.example.com/child1 <- Child Site 1
http://www.example.com/child2 <- Child Site 2

User1 logs on on http://www.example.com and gets redirected to Child Site 1 from wp-login. He leaves the site, but is still logged in, so he goes back to example.com, but he is logged on this time, but isn't currently getting redirected.

If there is a way to automatically redirect them to their childsite or a link on the main page, that would be fantastic. Thank you much.

  • Vaughan

    Hi @michael

    I don't believe this is possible easily.

    The problem is, users can be owners of many blogs, they can also be admins in multiple blogs & blogs do not have owners, they have admins, and as a blog can have many admins. How do you know which blog the user wants to go to? There is no way to determine who blog owners actually are.

    You can get a list of blogs the user belongs to, that's about it.

    Hope this helps

  • Michael

    Well. I'm currently using this code I found on the net in my mu folder.

    <?php
    function ds_login_redirect( $redirect_to, $request_redirect_to, $user )
    {
        if ($user->ID != 0) {
            $user_info = get_userdata($user->ID);
            if ($user_info->primary_blog) {
                $primary_url = get_blogaddress_by_id($user_info->primary_blog) . 'wp-admin/';
                if ($primary_url) {
                    wp_redirect($primary_url);
                    die();
                }
            }
        }
        return $redirect_to;
    }
    add_filter('login_redirect','ds_login_redirect', 100, 3);
    ?>

    Which will redirect the user to their primary childsite1 after logging in. But if they go back to the main page, it won't automatically redirect them. Is there a way to modify that code so that the user will be auto redirected to their primary blog when they go to the main page (not the child site)

  • Vaughan

    Hi

    That could work. But you'll need to edit your header template & add this to the nav menu part or wherever you want the link to appear. (I added a div so you can style or position it with CSS)

    if(is_user_logged_in()) {
        $user_info = get_userdata(get_current_user_id());
        if ($user_info->primary_blog) {
            $primary_url = get_blogaddress_by_id($user_info->primary_blog) . 'wp-admin/';
            if ($primary_url) {
                echo '<div class="home-link"><a href="' . $primary_url . '">Blog Home</a></div>';
            }
        }
    }

    Hope this helps

  • Michael

    How precisely would I go about that? I am not really that php savvy. Do I just make another php in notepad with that information and put it in my mu folder? How and what do I edit my header template with and how would I go about doing so?

    I would be satisfied with being able to make a link on my homepage, but would prefer if I could set it to redirect the user to the child site after going back to the original site.

    Say if the user was logged on and their login was remembered. If they were go to back to the main site, I would like them redirected to their primary blog.

    Thanks so much for the help. You folks are great!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.