Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'd like to prevent certain user roles from accessing the dashboard http://www.openeye.net/wp-admin/ at all. I've moved and restyled user profiles to a new page that's viewable on the site. How would I go about doing this?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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.

share|improve this answer
    
Excellent, however I'm getting a syntax error on the second line. –  Zach Shallbetter Jul 14 '11 at 21:23
    
Oh ok it's related to the extra ( after ('DOING_AJAX') –  Zach Shallbetter Jul 14 '11 at 21:58
    
Oh, sorry; that was intentional. There was supposed to be another one closing at the end. I added it to the answer. –  John P Bloch Jul 15 '11 at 15:06
    
Is there a reason this doesn't work with the 2011 theme and the members plugin? –  Zach Shallbetter Sep 9 '11 at 6:36
    
This doesn't seem to work on network sites, any idea why? –  Zach Shallbetter Oct 9 '11 at 21:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.