Hook
Remove WP Admin Access for any role
With this filter you can remove access – both visually and programmatically – to the WP Admin for any role defined. Usually you’d install a whole plugin for this feature but in fact it doesn’t need a plugin with lots of overhead.
This code also considers AJAX Events, and it can be adapted to any user role or further condition.
add_action('init','safe_remove_backend_admin_access_for_role'); function safe_remove_backend_admin_access_for_role(){ if( current_user_can('editor') || current_user_can('administrator') )//Your roles return; if( is_admin() && !defined('DOING_AJAX') ){//IMPORTANT! Front end AJAX events are excluded... if(isset( $_GET[ 'action'] ) && 'trash' == $_GET[ 'action'])//Perhaps you have a call to some WP Admin Operation that needs whitelisting... return; wp_redirect( home_url() ); exit; } }