我是这样做的:
// if admin send them to the dashboard, otherwise leave them on the frontend
add_action(\'wp_login\', \'rt_login_redirect\', 10, 2); //use this action if you want them to be redirected only after login but leave the ability to to to the dashboard later (ie changing profile or pw).
add_action( \'admin_init\', \'rt_login_redirect\' ); // use this action to completely dis-allow all others besides the admin to access the dashboard.
function rt_login_redirect($user_login, $user) {
if (!current_user_can(\'manage_options\')) {
wp_safe_redirect( home_url(), 302);
exit();
}
}
主要功能通过检查用户是否有能力管理选项来检查用户是否是管理员。如果他们没有该功能,那么该功能会将他们重定向到主页。如果他们这样做了,他们可以留在后端。
当有人尝试采取行动(如上所述)时,该功能将被激活(根据您的需要选择一个选项)