I have a very simple AJAX function that works fine when logged in as admin, but when logged in as a subscriber the call to admin-ajax.php returns a html page with the header and footer of my theme, and that's it.

By doing some wolf fencing I've tracked it down to line 37 of admin-ajax.php do_action( 'admin_init' );. It gets there and just returns.

  • Please post all of your code. It sounds like you have something hooked incorrectly but it is impossible to say for sure without more information.
    – s_ha_dum
    Feb 11 '13 at 14:21

If an AJAX function does not work properly, in most cases you forgot to allow Users with no or little privileges to access the function.

Adding the Callback Function is quite simple:

add_action('wp_ajax_my_action', 'my_action_callback');

Now you need to do the same thing for the "not-so-privileged" users:

add_action('wp_ajax_nopriv_my_action', 'my_action_callback');

With these two lines everything should work as expected.

  • No dice. It doesn't get as far as deciding whether or not it should be using "nopriv" callbacks (this happens at the very end of admin-ajax.php). I just gets to admin_init and fails there. Feb 11 '13 at 11:00
  • Try deactivating all Plugins, and see if the Problem still exists. And try switching back to TwentyTwelve.
    – fischi
    Feb 11 '13 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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