To lock subscribers and contributors out of the admin:
1 2 3 4 5 6 7 8 9 | function fwm_redirect(){ if( is_admin() && !defined('DOING_AJAX') && ( current_user_can('subscriber') || current_user_can('contributor') ) ){ wp_redirect(home_url()); exit; } } add_action('init','fwm_redirect'); |
Hope that helps. All roles give the user a capability that is the name of that role, so you can use any role name as a capability.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.