WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to keep all non-administrators out of the Wordpress admin panel by using a wp_redirect inside of an is_admin conditional. The problem is that a side effect of this if that non-admins can no longer use the file "admin-ajax.php" for ajax calls in Wordpress. It appears that a few people on the Wordpress forums are having the exact same problem lately.

Would anyone have a solution for this?

share|improve this question
up vote 8 down vote accepted

Check the DOING_AJAX constant:

function my_admin_init(){
    if( !defined('DOING_AJAX') && !current_user_can('administrator') ){
        wp_redirect( home_url() );
share|improve this answer
I'd switch to manage_options in case some plugin changes the name of the 'administrator' role. Anyway, I'd +10 this if i could :) – kaiser Aug 17 '11 at 9:35

Your Answer


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.