I want to block multiple user roles from accessing the WordPress dashboard, I have a custom role, and I want to block it along with other roles, but I don't know how to edit the code.
the code below has one role (shopkeeper) I want to add more roles how can I do that?
function wpse66094_no_admin_access() {
$redirect = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : home_url( '/' );
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
if($user_role === 'shopkeeper'){
exit( wp_redirect( $redirect ) );
}
}
add_action( 'admin_init', 'wpse66094_no_admin_access', 100 );
in_array()
. Alsoexit()
expects a string or int parameter whilewp_redirect()
returns a string.