Redirect user from main blog login to the site they are registered to

Hi,

I run a multisite installation and trying to redirect users from main blog login to the site which they are registered to. I have set the option in Multisite Privacy to "Only allow a registered user to see a site for which they are registered to. "

I have tried using these codes in my mu-plugins folder without success. The users are redirected to the main blogs frontpage.

<?php
/*
Plugin Name: Redirect Users to Primary Site
Plugin URI:
Description: Never see "you do not currently have privileges on this site" when logging in on your multisite ever again!
Version: 2014.06.02
Author: khromov
Author URI: https://profiles.wordpress.org/khromov
License: GPL2
*/

/* https://premium.wpmudev.org/forums/topic/redirect-users-to-their-blogs-homepage */
add_filter('login_redirect', function($redirect_to, $request_redirect_to, $user)
{
if (!is_wp_error($user) && $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;
}, 100, 3);

Any suggestions why this is not working? I have set up the site to use subdomains.