Here’s a quick plugin from this thread. Create this as the file redirect-users.php in /wp-content/mu-plugins/
From here on your users will be redirected to their primary site upon logging in, and you will never see that nagging “You attempted to access the (main network site) dashboard, but you do not currently have privileges on this site.” error!
<?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
*/
/* http://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);
The only shortcoming with this plugin is that it will redirect admins back to their primary site (blog id = 1) if they sign onto another site. To fix this we need a slightly more complicated solutions, which checks if the user has access to the blog they are logging in to and only if they do not have access do you redirect. If you prefer this behaviour you can use this version of the plugin:
<?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
*/
/* http://premium.wpmudev.org/forums/topic/redirect-users-to-their-blogs-homepage */
add_filter('login_redirect', function($redirect_to, $request_redirect_to, $user)
{
global $blog_id;
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/';
$user_blogs = get_blogs_of_user($user->ID);
//Loop and see if user has access
$allowed = false;
foreach($user_blogs as $user_blog)
{
if($user_blog->userblog_id == $blog_id)
{
$allowed = true;
break;
}
}
//Let users login to others blog IF we can get their primary blog URL and they are not allowed on this blog
if ($primary_url && !$allowed)
{
wp_redirect($primary_url);
die();
}
}
}
return $redirect_to;
}, 100, 3);