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 have used this function below for a while now on normal WordPress installs.

It simply blocks users with specific user roles, and redirects them to the home page of the site.

function wpse23007_redirect(){
  if( is_admin() && !defined('DOING_AJAX') && ( current_user_can('subscriber') || current_user_can('media') ) ){
    wp_redirect(home_url());
    exit;
  }
}
add_action('init','wpse23007_redirect');


But when I install this on a sub theme in my WordPress Multisite, even though I am a superuser, it is blocking me from the dashboard of my sub theme.

Can anyone help me understand why this is and how to change the above so it doesn't block me?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

All your role checks are relative to the user roles in the sub site in which I assume you are not a user. You should also check for is_super_admin()

  if( !is_super_admin() && (is_admin() && !defined('DOING_AJAX') && ( current_user_can('subscriber') || current_user_can('media') ) ) ){
    wp_redirect(home_url());
    exit;
  }
share|improve this answer
    
Works perfect thank you! –  Joshc Feb 6 '13 at 9:30

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.