My Account

Forums

Forums General Role-based redirection after Login Reply To: Role-based redirection after Login

#49303
eugenek
Participant

For multiple redirection, I suppose the following code would apply:

    $admin_redirect_url = '/redirect-admin/';
    $author_redirect_url = '/redirect-author/';
    $subscriber_redirect_url = '/redirect-subscriber/';
    // etcetera

            // Check user role
            if( in_array( 'administrator', $user->roles ) ) {
                $field_error_action_array[] = array(
                    'action' => 'redirect',
                    'url' => $admin_redirect_url
                );
            }

            if( in_array( 'author', $user->roles ) ) {
                $field_error_action_array[] = array(
                    'action' => 'redirect',
                    'url' => $author_redirect_url

            }

            if( in_array( 'subscriber', $user->roles ) ) {
                $field_error_action_array[] = array(
                    'action' => 'redirect',
                    'url' => $subscriber_redirect_url
                );
            }

am I correct?