When new site is created on my multisite installation, I automatically add the new user to the main site (because I need him to order the product):
add_user_to_blog( 1, $user_id, 'customer' );
I'd like to have the users automatically login them to all their sites, as soon as they login to one of the sites they belong to.
I hoped to hook to the wp_login
action and just set the auth_cookie
for each sites the user belongs to, something along these lines:
add_action('wp_login','autologin');
function autologin($user_login, $user) {
$user_blogs = get_blogs_of_user($user->ID);
foreach ($blogs as $blog) {
switch_to_blog($blog->blog_id);
wp_set_current_user ( $user->ID );
wp_set_auth_cookie ( $user->ID);
restore_current_blog();
}
}
That doesn't work though. Is there a workaround for this?
define('COOKIE_DOMAIN',false);
set to allow displaying multisite blogs on different domains.