This is what i am using;
add_action('init', 'blockusers_init');
function blockusers_init() {
if (is_admin() && !current_user_can('administrator') &&
!(defined('DOING_AJAX') && DOING_AJAX)) {
wp_redirect(home_url());
exit;
}
}
It’s possible the best one.
EDIT : You need a custom login page for reach wp-admin
. This code redirect to homepage if you enter directly to wp-admin
.