Home › Forums › Legacy Support › Support queries › How-to & Troubleshooting › Redirect after Login by user roles
Tagged: login, redirect, roles, user roles
- This topic has 10 replies, 5 voices, and was last updated 5 years ago by logan.
-
AuthorPosts
-
January 5, 2017 at 11:36 am #88261reventixParticipantHi, I want that the users will redirect to other urls by user roles I added this code to child theme, functions.php bud its not working: add_filter('login_redirect','wplms_custom_login_redirection',999,3); function wplms_custom_login_redirection($redirect_url,$request_url,$user){ global $user; if ( isset( $user->roles ) && is_array( $user->roles ) ) { if ( in_array( 'partner', $user->roles ) ) { // redirect them to the default place $data_login = get_option('/kurs/partner'); return get_permalink($data_login[0]); } else { return home_url(); } } else { return $redirect_to; } } Can you helb me please?January 5, 2017 at 1:41 pm #88355Skywalker [ ex VibeThemes]ParticipantThis is already available in the LMS Settings.January 5, 2017 at 2:19 pm #88385reventixParticipantNo no no... I have 5 user roles and I want that each other redirect to other URLs when they login... e.g.: User role 1 redirect to /course/professional User role 2 redirect to /course/bronze User role 3 redirect to /course/silver and so on... How to do that?January 6, 2017 at 4:11 am #88473H.K. LatiyanParticipantYou have created 5 custom user roles and want custom redirect for all the user roles. This is a customization and doesn't come under theme support. Wplms only have student and instructor user roles only, so a better solution will be to use some wordpress third party plugin for this purpose. You can search it in wordpress plugins directory.January 6, 2017 at 4:14 am #88474H.K. LatiyanParticipantIn the code you shared above you can try giving the priority as 1 and after redirecting exit the code.December 14, 2019 at 6:22 pm #236912No OneSpectatorHello, Please share a working code, I had to create a role for a group of students with the same way and need to redirect them to a custom page ThanksDecember 16, 2019 at 7:07 am #236970loganMemberHello,
You have created 5 custom user roles and want custom redirect for all the user roles.
This is a customization and doesn't come under theme support.
Wplms only have student and instructor user roles only, so a better solution will be to use some wordpress third party plugin for this purpose.
You can search it in wordpress plugins directory.
when user is registered then use this code in wp-admin >> plugins >wplms-customizer plugin > customizer.phpadd_filter('login_redirect','wplms_custom_login_redirection',10,3);
function wplms_custom_login_redirection($redirect_url,$request_url,$user){
global $user;
$url = "https://www.google.com";if ( isset( $user->roles ) && is_array( $user->roles ) ) {
if ( in_array( 'partner', $user->roles ) ) {
return wp_redirect( $url );
exit;
} else {
return wp_redirect( $url );
exit;
}else {
return wp_redirect( $url );
exit;
}
}
}
December 17, 2019 at 2:11 pm #237141No OneSpectatorHere's my solution :
function my_login_redirect( $url, $request, $user ){ if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) { if( $user->has_cap( 'student')) { $url = home_url('/student-page/'); } elseif( $user->has_cap( 'partner')) { $url = home_url('/partner-page/'); }elseif( $user->has_cap( 'otherpartner')) { $url = home_url('/other-partner/'); }else { $url = home_url('/global-page/'); } return $url; }} add_filter('login_redirect', 'my_login_redirect', 10, 3 );
Thanks for helpDecember 18, 2019 at 6:13 am #237164loganMemberthis will also work. please let me know if it is resolved so that i can close this topic.December 18, 2019 at 7:18 am #237177No OneSpectatorYes, it works Just sharing it, Thanks Logan, it's resolvedDecember 18, 2019 at 12:22 pm #237203loganMemberfor all our efforts, i hope you wouldn't mind writing a detailed review about your experience with WPLMS and our customer support.
Here: https://themeforest.net/item/wplms-learning-management-system/reviews/6780226
If I can be of assistance, please do not hesitate to contact me again.
Closing this topic.
best regards
-
AuthorPosts
- The topic ‘Redirect after Login by user roles’ is closed to new replies.