Modifying a plugin to redirect a user back to their primary blog if they are logged in

Hi all,

I am disgustingly new at Wordpress, plugins, and getting my site to do what I want. But this CMS has so many opportunities, I had to stick with it.

So I have a Multisite setup. Users are added by site admins, which in that process are a part of that child site by way of primary_blog. I have one parent page that all users log in through, and once logged in, they are automatically redirected to their primary_blog (primary site).

I am using the following code in my mu folder

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) . '';
            if ($primary_url) {
    return $redirect_to;
add_filter('login_redirect','ds_login_redirect', 100, 3);

So that when a user reaches the main site and clicks on the login button, they are logged in and redirected to their primary_blog.

I have blocked out My Sites and Dashboard to regular users. So my issue is that while a user is logged in, if they leave the site and come back to the primary site, they are not returned to their primary blog.

I am looking to modify the above code in such a way that if the user returns to the main site they are automatically redirected to their primary blog if they are logged in.

I have the following code that was meant to help, but it doesn't do what I need it to do and I am not sure how to incorporate it.

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>';

Any help would be so much appreciated. I would like just something I can drop into the MU folder, other than that I'd need help with instructions. I'm such a newbie, I feel terrible, but after racking my brain for a while, I thought the humble thing to do is ask for help.

Thanks everyone for their time and dedication!