admin管理员组文章数量:1318025
I want my site to redirect after login to site_url('/') for all users except 'administrator' I also want the admin_bar showing for certain roles ie event_planner. It is all working except that when and event_planner logs on and then clicks on the admin bar to go into admin it redirects to '/'. The hook being used to redirect is 'admin_init' which is clearly wrong. Is there another hook I could use to initially redirect to / on login but not when pressing the dashboard on the admin bar.
Thanks
I want my site to redirect after login to site_url('/') for all users except 'administrator' I also want the admin_bar showing for certain roles ie event_planner. It is all working except that when and event_planner logs on and then clicks on the admin bar to go into admin it redirects to '/'. The hook being used to redirect is 'admin_init' which is clearly wrong. Is there another hook I could use to initially redirect to / on login but not when pressing the dashboard on the admin bar.
Thanks
Share Improve this question asked Oct 28, 2020 at 18:07 PeterBPeterB 72 bronze badges1 Answer
Reset to default 3There's a filter called login_redirect
.
add_filter( 'login_redirect', 'wpse377295_login_redirect', 10, 3 );
function wpse377295_login_redirect( $url, $request, $user ) {
if ( is_wp_error( $user ) ) {
// It's possible that the $user param is a WP_Error. If so, bail out.
return $url;
}
if ( ! user_can( $user, 'update_core' ) {
// Only admin users can update core, normally.
$url = site_url( '/' );
}
return $url;
}
There's a more complete example in the filter documentation's User Contributed Notes.
References
login_redirect
user_can()
本文标签: hooksRedirecting from login
版权声明:本文标题:hooks - Redirecting from login 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742031512a2416527.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论