This thread is resolved. Here is a description of the problem and solution.
Problem:
The issue here is that the user wanted to redirect his users after they had logged in based on their roles.
Solution:
To do this you can follow the example in the link below.
function my_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( 'administrator', $user->roles ) ) {
// redirect them to the default place
return $redirect_to;
} elseif ( in_array( 'client', $user->roles ) ) {
return home_url('/wp/client/dashboard/');
}elseif( in_array( 'legalpro', $user->roles ) ){
return home_url('/wp/legal-professional/dashboard/');
}
} else {
return $redirect_to;
}
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
Add it to your functions.php file.
This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
We are having issues with our login form. We currently have two user roles set up: Client and Legal Professional. Each of these user roles have different access groups configured.
Both user types are using the same login form. Here is the code for the login form:
[wpv-conditional if="('[wpv-current-user info='id']' eq '')"]
Login
[wpv-login-form]
Forgot Password?
[wpv-forgot-password-form]
[/wpv-conditional]
[wpv-conditional evaluate="false" if="('[wpv-current-user info='id']' eq '')"]
You are logged in.
[/wpv-conditional]
When a user logins, the site should redirect them to the appropriate dashboard (/wp/client/dashboard) OR (/wp/legal-professional/dashboard). Here is the code being used for the redirect:
Currently, the site always redirects the user to /wp/legal-professional/dashboard, regardless of the user type. The Client user role does not have access to this page, so they are shown the 404 page.
I can’t find the setting or problem that is redirecting all users to the same URL. Any help is greatly appreciated. Thanks.
Thanks Shane. That helps, but it still isn't redirecting to the correct URL. The $user = wp_get_current_user(); line seems to be necessary, because now that I have that added, every login is redirecting to the homepage (found in the else brackets). Therefore, I'm thinking the code used to specify user roles is not working correctly. I checked the slugs (see attached) and everything appears to be correct.
I wasn't sure where to add the if statement that you provided, and if I would be doing that for every user role (administrator, legal professional, & client).
Thanks for this information. The first block of code works. As for the second block of code, the legal professional role is redirecting to the correct location, but the client user role does not redirect to the correct location. When I login as a client, I am redirected to /wp/legal-professional/dashboard when I should be redirected to /wp/client/dashboard.