Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Redirect multi-site usert to theyr blog WordPress

  • SOLVED

Hi,

I have a multi-site install setup like that


I have one super admin user that can acces all the site and then 1 user admin registred by site

mainsite.domain.com ---> user1admin
site2.secdomain.com ----> user2admin
site3.thirddomain.com ---> user3admin
site4.fourthdomain.com ---> user4admin

What I would like to do is the following

when any of the "admin" user try to login from any site wp-admin they get logged in and redirected to their blog.

for example if user1admin login from site4.fourthdomain.com/wp-admin it would get redirected to mainsite.domain.com dashboard (whithout having to type his login/pass again)

or another example if user3admin try to login from mainsite.domain.com/wp-admin it would get redirected to site3.thirddomain.com dashboard without having to enter his infos again.

In this multi-site install there would be no more site or user added over time.

Thanks for your help

Answers (3)

2014-06-05

Romel Apuya answers:

Hi,

I think this one should do it

function primary_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) . 'wp-admin';
if ($primary_url) {
wp_redirect($primary_url);
die();
}
}
}
return $redirect_to;
}
add_filter('login_redirect','primary_login_redirect', 10, 3);

2014-06-04

Arnav Joy answers:

try this and please modify the username and the redirect domain as per your need

<?php

function my_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
global $current_user;
get_currentuserinfo();

if( $current_user->user_login == 'user1admin' )
return 'http://mainsite.domain.com';
else if( $current_user->user_login == 'user3admin' )
return 'http://site3.thirddomain.com';
else
return $redirect_to;

}

add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
?>


l.pirondini comments:

Hi, Thanks for the answer this does redirect the user to the correct domain.com/wp-admin but dosen't log him in.


Arnav Joy comments:

no it will not login to other domain it is just for redirection

2014-06-04

Luis Abarca answers:

Had you tried to add a custom field to user profile with the URL of the site, then redirect the user to that URL with [[LINK href="http://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect"]]login_redirect[[/LINK]].