0

I'm stumped trying to redirect my users to a specific page on their primary blog when they login to the root/main site on a MU setup. I have the site editors with a specific 'editor' role and then tenants with 'subscriber' role. The following code (in a plugin in MU folder) redirects the users with one of the 3 editor roles but will not redirect those with 'subscriber' role. Any help would be greatly appreciated! Thanks!

public function login_redirect($redirect_to, $requested_redirect_to, $user) {
    $user = wp_get_current_user();
    
    if ( (in_array( 'editor-tier3', $user->roles )|| in_array( 'editor-tier2', $user->roles ) || in_array( 'editor-tier1', $user->roles )))  {
        
        if ($user->ID != 0 && $user->ID != 1) {
    
            $user_info = get_userdata($user->ID);
    
            if ($user_info->primary_blog) {
    
                $primary_url = get_blogaddress_by_id($user_info->primary_blog) . 'management-dashboard/';
    
                if ($primary_url) {
    
                    wp_redirect($primary_url);
    
                    die();
    
                }
    
            }
    
        }
    }
    
    elseif (in_array('subscriber', $user->roles))  {
    
        if ($user->ID != 0 && $user->ID != 1) {
    
            $user_info = get_userdata($user->ID);
    
            if ($user_info->primary_blog) {
    
                $primary_url = get_blogaddress_by_id($user_info->primary_blog) . 'tenant-dashboard/';
    
                if ($primary_url) {
    
                    wp_redirect($primary_url);
    
                    die();
    
                }
    
            }
    
        }   
    
        
    }
        
       // return $redirect_to;
    
    }

1 Answer 1

0

I opted to create two functions - 1 to redirect the user based on their primary blog and then a second to redirect any attempt at accessing the /wp-admin/ (wordpress redirects users to admin on login) to a different page based on their role. Seems to work. I think there's some sort of two step process in wordpress login that's tripping up role validation so this is the next best thing

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.