Try this. It works for me.
add_filter( 'login_redirect', 'redirect_non_admin_to_dashboard'), 10, 3 );
function redirect_non_admin_to_dashboard($redirect_to, $requested_redirect_to, $user ) {
global $user;
if( ! isset( $user->ID ) ) {
return $redirect_to;
}
if ( ! in_array( 'author', (array) $user->roles ) ) {
$redirect_to = site_url().'/dashboard-teacher';
}elseif( in_array( 'subscriber',(array) $user->roles ) ){
$redirect_to = site_url().'/dashboardwwp-student';
}else{
$redirect_to = site_url();
}
return wp_validate_redirect( $redirect_to, home_url() ); // return a safe redirect url between the site.
}
Related Posts:
- Is it possible to get a user with just the password field?
- Is possible to allow user to login with different role?
- Does wordpress support natively the concept of logging-in users? (not admins, but users of the website)
- If the current user is an administrator or editor
- Editor can create any new user except administrator
- How to allow an user role to create a new user under a role which lower than his level only?
- Remove Ability for Other Users to View Administrator in User List?
- Find out if logged in user is not subscriber
- Groups of capabilities: users with multiple roles?
- User-edit role setting distinct from wp_capabilities? [closed]
- Replacing the WordPress password validation
- Allowing users to edit only their page and nobody else’s
- alphabetically order role drop-down selection in dashboard
- WordPress auto login after registration not working
- Execute a function when admin changes the user role
- How to let contributors to create a new revision(draft) editing their published posts
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- What the user_status column?
- Hide Admin Menu for Specific User ID who has administrator Role
- Allow up to 5 Concurrent Login Sessions
- How to hide media uploads by other users in the Media menu?
- Show admin bar only for some USERS roles
- Grouping users under parent user
- How to update user role without logout
- How to check user role without using current_user_can()
- Why does is_user_logged_in() return false after redirect from another site?
- Do not allow users to create new posts and pages
- How to redirect a specific user after log-in?
- \WP_User Object | What’s the Difference Between {caps} and {allcaps}?
- Force users to complete their profile after they register? How to
- How to enable the theme editor cap for an editor role?
- How to assign capabilities to user NOT to User Role
- How to assign an additional/extra/second user-role to multiple users (of a specific user-role)
- How to stop a user from updating the post date
- BuddyPress | Check if user is in current group [closed]
- Pre-populate Username Field
- Return ID of authors who have at least one post
- WordPress edit_user_profile_update update secondary role
- How to keep track of user logins?
- How do I properly format the user_role array?
- How-to Delay The Capability To Publish Posts?
- Get user info outside WordPress
- How can I secure a WordPress blog using OpenID from a single provider?
- How to customize wp_signon()
- Is there a simple way to manage capabilities per user?
- How to get the Role Name of the current user? (WordPress)
- set_role has no effect
- Check for user meta data at Login
- WP_User->add_role producing unexpected results
- How can I check if the admin bar is visible to the current user?
- Redirect User to Homepage if no other redirect is specified
- Can I create users that have access to *some* other users posts instead of all other users posts?
- My custom page template with is_user_logged_in() does not detect that I’m logged in
- Set default page for user account in admin
- Use phpbb user database for WordPress
- WordPress to use Drupal users’ credentials
- Users roles, make a page belonging to multiple users
- Tagging users in WordPress
- Redirect after users complete profile form
- Share user table from WP with Drupal
- How do I list in the backend all users that were assigned to a custom role?
- How can I allow password reset based on logins containing the @ character?
- A way to count logged in users and display count?
- stop login if user_status equal zero
- How to add local users to wordpress without email password?
- Hide everything on site for visitors except specific page IDs
- Get User Role by ID not working
- the_author_meta(‘user_url’, $author->ID) not working properly. how can I solve this?
- Getting users by specific capability, not role
- add_cap not working with Shop Manager role
- Restricting frontend acess based on user role otherwise redirect to login form
- How do i make my wordpress website private?
- Managing Users and Creating Groups [closed]
- Redirect user to login before viewing custom post
- Change the user_login at registration
- How to disable a specific page for a specific user
- Are User Levels Still Currently Used?
- Max no of simultaneous active sessions for a single user
- Error: How to allow the “contributor” to upload media in wordpress
- Remove Capabilities from WP admin for specific user role
- When I try to login in wordpress it is showing “USER Doesn’t Exists”
- Updating wp_user_level on user update
- wordpress user roles are not working
- Displaying different in-page content to cliente/admin
- Should I encrypt the response that triggers an Ajax action? Is nonce sufficient?
- Fix permissions for users role
- Redirect subscribers to last viewed page after log-in
- User capability for editing their own comments
- What are some best practices for user exit strategy?
- Is there a way to identify a user in a custom REST API method? [duplicate]
- wordpress disable login for unverified user
- Problem with automatic role change through cron job
- Reset Password policy
- Allow Contributors to Upload Files
- Rewrite Rules and Login Issue
- How can I allow an User to publish only 5 posts per month?
- Add a role and give admin priviledges
- Where are $current_user->allcaps set?
- How change user type from contributor to author
- Use WordPress Login for a non-wordpress site