admin管理员组文章数量:1026978
I want to make a multi-user website. Different types of users are Students, Teachers, Parents, Admin and counselor. I want to redirect each user to specific pages based on their type after logging in. How do I proceed? Is any plugin available?
How do I carry out registration and login?
Say, students should be redirected to a page student.php
if and only if he is a student.
Teachers should be redirected to say teacher.php
.
All types of users have different dashboards.
I want to make a multi-user website. Different types of users are Students, Teachers, Parents, Admin and counselor. I want to redirect each user to specific pages based on their type after logging in. How do I proceed? Is any plugin available?
How do I carry out registration and login?
Say, students should be redirected to a page student.php
if and only if he is a student.
Teachers should be redirected to say teacher.php
.
All types of users have different dashboards.
Share Improve this question edited Jun 19, 2018 at 12:27 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Jun 19, 2018 at 12:21 Kanishk JainKanishk Jain 11 silver badge2 bronze badges 1- You can save their roles in meta fields and on login you can check the field and add the redirection accordingly. – Akshat Commented Jun 19, 2018 at 12:33
1 Answer
Reset to default 2You would make use of the login_redirect filter.
The example in the documentation looks a lot like what you are asking:
/**
* Redirect user after successful login.
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user's data.
* @return string
*/
function wpse306427_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
if (isset($user->roles) && is_array($user->roles)) {
//check for subscribers
if (in_array('subscriber', $user->roles)) {
// redirect them to another URL, in this case, the homepage
$redirect_to = home_url();
}
}
return $redirect_to;
}
add_filter( 'login_redirect', 'wpse306427_login_redirect', 10, 3 );
You would put this code in a plug-in or in your theme's function.php.
I want to make a multi-user website. Different types of users are Students, Teachers, Parents, Admin and counselor. I want to redirect each user to specific pages based on their type after logging in. How do I proceed? Is any plugin available?
How do I carry out registration and login?
Say, students should be redirected to a page student.php
if and only if he is a student.
Teachers should be redirected to say teacher.php
.
All types of users have different dashboards.
I want to make a multi-user website. Different types of users are Students, Teachers, Parents, Admin and counselor. I want to redirect each user to specific pages based on their type after logging in. How do I proceed? Is any plugin available?
How do I carry out registration and login?
Say, students should be redirected to a page student.php
if and only if he is a student.
Teachers should be redirected to say teacher.php
.
All types of users have different dashboards.
Share Improve this question edited Jun 19, 2018 at 12:27 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Jun 19, 2018 at 12:21 Kanishk JainKanishk Jain 11 silver badge2 bronze badges 1- You can save their roles in meta fields and on login you can check the field and add the redirection accordingly. – Akshat Commented Jun 19, 2018 at 12:33
1 Answer
Reset to default 2You would make use of the login_redirect filter.
The example in the documentation looks a lot like what you are asking:
/**
* Redirect user after successful login.
*
* @param string $redirect_to URL to redirect to.
* @param string $request URL the user is coming from.
* @param object $user Logged user's data.
* @return string
*/
function wpse306427_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
if (isset($user->roles) && is_array($user->roles)) {
//check for subscribers
if (in_array('subscriber', $user->roles)) {
// redirect them to another URL, in this case, the homepage
$redirect_to = home_url();
}
}
return $redirect_to;
}
add_filter( 'login_redirect', 'wpse306427_login_redirect', 10, 3 );
You would put this code in a plug-in or in your theme's function.php.
本文标签: Redirect each user to specific pages based on their role
版权声明:本文标题:Redirect each user to specific pages based on their role 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745648304a2161158.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论