• 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: https://www.example1.com/wp-admin/index.php)they belong to. I tried different ways to achieve this but none of them is 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 );
                exit;

    Let me know if it is possible?

    • This topic was modified 4 years, 3 months ago by Jan Dembowski. Reason: Moved to correct forum
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    You seem to have the right idea, but it’s not clear in what context your code executes. I think the problem is how you manage the redirect. Instead of doing so yourself, hook the filter “login_redirect” and use your code as the callback, returning the appropriate link to the filter instead of redirecting yourself.

    This is my problem too. I haven’t found any solution for now.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WordPress Multisite: Redirects users after login to the site’s admin dashboard’ is closed to new replies.