I want to let the users log in through the main site(www.example.com/wp-admin), Once the user successfully logged In, I want to redirect them to the site admin(ie: www.example1.com/wp-admin/index.php)they belong to. I tried different ways to achieve this but none of them are working so far. Here is the way I do..

// fetch the user' site id and redirect to the site.
$user_blogs = get_blogs_of_user( $userID );

if( ! empty( $user_blogs ) ) {
    $siteInfo = array();
    foreach( $user_blogs as $site_id => $site_values ) {
        $siteInfo[] = $site_values->siteurl;
    $user_site = $siteInfo[0];
    $redirect_url = $siteInfo[0] . "/wp-admin";

// set the cookies
wp_set_auth_cookie( $user->ID, true, false );

// override the cookie domain
define( 'COOKIE_DOMAIN', $user_site );
define( 'COOKIEPATH', '/' );
define( 'COOKIEHASH', md5( $user_site ) ); 

// redirect users to their site admin dashboard.
wp_safe_redirect( $redirect_url );


Let me know if it is possible?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.