function redirect_non_admin_user(){ if ( !defined( 'DOING_AJAX' ) && !current_user_can('administrator') ){ wp_redirect( site_url() ); exit; } } add_action( 'admin_init', 'redirect_non_admin_user' );
Reference: https://stackoverflow.com/questions/9408334/wordpress-admin-ajax-results-in-error-302-redirect