admin管理员组文章数量:1318325
I'm trying to avoid that subscriber users had access to admin. I'm using the following code:
add_action( 'admin_init', 'lr_no_admin_u_access', 100 );
function lr_no_admin_u_access() {
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
$redirect = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : site_url();
if($user_role !== 'editor' && $user_role !== 'administrator'){
wp_logout();
wp_safe_redirect($redirect);
exit;
}
}
When a user navigates to '/wp-admin', should be logged out and redirected to the home page. Instead, a white page full of notices and warnings appears. Examples of errors:
Notice: Undefined offset: 2 in /home/[site]/public_html/wp-admin/includes/plugin.php on line 1911
Warning: Cannot modify header information - headers already sent by (output started at /home/[site]/public_html/wp-admin/includes/plugin.php:1911) in /home/[site]/public_html/wp-includes/functions.php on line 6270
... And many more. and many more. Why? How to avoid?
本文标签: wp adminHow to logout the current user without notices and warnings
版权声明:本文标题:wp admin - How to logout the current user without notices and warnings? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742034083a2417004.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论