add_action( 'admin_init', 'restrict_admin_with_redirect', 1 );
function restrict_admin_with_redirect() {
if ( is_user_logged_in() && is_admin() ) {
$user = wp_get_current_user();
if ( in_array( 'subscriber', $user->roles, true ) ) {
wp_safe_redirect( home_url(), 301 );
}
}
}