I have a site where I want some users to have the role type of admin but still not be able to access the admin area (don't ask!) This is more of a temporary fix whilst my new site is being built.
I am using this code at the moment which blocks everyone to the admin area unless role type is admin - but how can I block admin unless username is 'mack' for example.
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;
}
}
Obviously the user still needs to access all other front end pages of the site, just not the admin area.