Wanting to redirect user to their sub site based on the credentials entered in a Multi Site network.

Hello, my question involves redirecting a user from the Main Site in my Multi site network to the user's specific sub site based on the credentials entered. To help out, here is my scenario.

I have a Multi Site network setup with a Main Page that is my public facing webpage. This webpage also has a login link that I would like to redirect and auto login a user to their specific sub site based on their credentials entered in the login link. The credentials entered are the key to determining the sub site that the user is taken too.

I was able to do this with a single site using plugins and redirecting the user to a specific page but I need to scale up to individual user sub sites instead of user pages. The plugins I used for the single site setup don't seem to work the same in the multi site environment.

I'm using Godaddy for my hosting and it only allows me to install multi site using sub directories, no option to us sub domains.

Does the Pro Sites plugin or the Membership plugin offer the multi site functionality I'm looking for? I've researched this for a while now and I'm not able to find a resolution that fits exactly what I'm looking for. Or it could be that I have found the resolution but don't quite understand it enough to realize that is the answer to my needs.

Any advise or guidance you can provide would be greatly appreciated!

Thanks

  • Ash
    • WordPress Hacker

    Hello John

    Please try the following code:

    function go_to_primary_blog($redirect_to, $request, $user){
    $user_info = get_userdata($user->ID);
    return get_blogaddress_by_id($user_info->primary_blog) . 'wp-admin';
    }
    add_filter('login_redirect', 'go_to_primary_blog', 10, 3);

    You can use this code in your child theme's functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.