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 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.

share|improve this question
    
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
add comment

1 Answer

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.

share|improve this answer
    
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. –  Mark Webster 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
add comment

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.