To lock subscribers and contributors out of the admin:
function wpse23007_redirect(){
if( is_admin() && !defined('DOING_AJAX') && ( current_user_can('subscriber') || current_user_can('contributor') ) ){
wp_redirect(home_url());
exit;
}
}
add_action('init','wpse23007_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.
Related Posts:
- Given multiple admin accounts, how can I make it so that only admin with X username can edit posts
- How to Change the Default Home Page for the WordPress Dashboard?
- 3.3: How do you hide the new dashboard welcome panel?
- Prevent author from changing their posts if admin has modified
- Make A WordPress Page Accessible To Admins Only, Redirect Other User Roles
- How to remove administrator role in settings -> general -> New User Default Role?
- Create un-removeable user
- How can we customize the logo and some text on the welcome screen?
- Can I set a default dashboard layout for all users?
- Custom CSS In Admin Only For Certain Roles
- Remove ability to access certain admin menus
- Remove admin AND editor from the “change role to” menu in user listing
- Appearance->Editor not visible
- How to remove “Super Admin” from All Users for those that are not a “Super Admin”?
- Customize the upload screen
- Blocking Administrative Access to Authors and Subcribers?
- Customize Admin Users Screen based on Role
- Make certain pages uneditable by editors?
- Which hook for processing plugin page form data?
- Restrict dashboard access for specific user roles to specific actions
- How can I restore admin capabilities?
- How to solve 500 Error on WordPress Admin Dashboard due to time-out on getdirsize
- What determines whether admin toolbar is shown to a logged-in user?
- How to get view count of every page on site and add that (increasing) number to Dashboard Widget
- How do you set up a WordPress blog with multiple authors to allow something like StackExchange’s “community wiki” feature?
- Dashboard menu missing
- Can’t access dashboard as administrator, login as any other level works though
- Get post attached image to display in admin dashboard
- WordPress Remove Submenus
- Continuous Login Sessions For Super Admins Across Multi-Site Network of Sites
- Modifying the built-in behavior of ajax tag type-ahead functionality of WordPress
- Only Admin can Edit, Delete or Update
- add_cap for editor but no admin role
- Shared account / dual blogging in WordPress
- How to activate the dashboard
- Bind custom role to admin page
- remove menus for a specific role?
- Backend Checkboxes working – but not visual?
- current_user_can(‘administrator’) not working in custom login
- Show global Message in User Profiles with admin only Input field in WordPress Backend
- How to make sure your admin doesn’t hi-jack you site?
- Redirect admin 403 “Cheatin uh?” admin pages
- How should I setup the “Users” area to hand over to a client?
- solution to prevent specific admins from altering site contents
- Admin user roles/permissions
- Posts in sidebar only by admin
- Top toolbar is not showing in wordpress admin panel
- Want to know who is login Admin/User
- Dashboard RSS Widget Overhaul
- Extending the user profile [closed]
- How To Create WordPress Dashboard Item
- Adding a WordPress Admin Dashboard to my local wordpress site
- Redirect non-admin after login, and in url – /admin
- Hide top admin panel for non admin and non editors
- How can I create multiple different admin roles with their own capabilities
- Sortable admin columns by 0.00 number
- WordPress4.1.15 Dashboard links not working
- Different role for free and pro users in wordpress without using bbpress
- Unable to render Admin Notices
- My code for creating an admin option doesn’t work
- WP Logs me out after updating anything on dashboard
- TinyMCE buttons broken
- WordPress admin panel is blank
- Different customer login form than administrator login form?
- What are the standard admin CSS id/class tags?
- How to filter post listing (in WP dashboard posts listing) using a custom field (search functionality)?
- Admin Ajax is returning 0
- Add custom column to Users admin panel
- wp_verify_nonce vs check_admin_referer
- Add a Separator to the Admin Menu?
- How to determine whether we are in add New page/post/CPT or in edit page/post/CPT in wordpress admin?
- Possible to hide Custom Post Type UI/Menu from specific User Roles?
- how to know if admin is in edit page or post [duplicate]
- Modal window from within WordPress admin
- Where in WP can I check history or log of updates of plugins etc?
- Adding a custom admin page
- How does admin-ajax.php work?
- Remove update nags for non-admins [duplicate]
- Give Editor Access To Sidebar
- How to remove entire admin menu?
- How can I speed up my WP admin section?
- How to pass parameters to admin_notices?
- Admin: very slow edit page caused by core meta query
- if admin is logged in
- Search posts by ID in admin
- Setting admin edit panels & metaboxes positions and visibility for ALL users and admins
- Find out which moderator approved comment?
- The website cannot display the page
- How To Remove WordPress Version From The Admin Footer
- Sort pages in loop by admin’s page attributes order field?
- Edit “thank you for creating with WordPress” in version 3.3.1
- Hide other users’ posts in admin panel
- Set Default Admin Colour For All Users
- Editor Styles and Typekit
- WordPress admin stylesheet
- This CSS Stuffing Works, But Is This A Good Practice?
- Is it possible to create a WordPress tour? V3.3.1
- Securing Admin Accounts – Username Discovery
- is_admin() returns true when using admin-ajax.php from front end script
- How to save dismissable notice state in WP 4.2?