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 know this has come up a number of times but it is driving me nuts. I've spend hours trying to debug it.

My AJAX isn't working for non-logged in users.

Here's me action:

add_action('wp_ajax_nopriv_ah_update', array($tracker, 'update_tracking'), "1");
add_action('wp_ajax_ah_update', array($tracker, 'update_tracking'), "1");

I've placed them inbetween is_admin and out of it. I've taken the server side code out of the class and put it in its own function. But nothing works.

I should state that it works fine for all logged-in users

I've done a var_dump() on $_GET['request'] and it all looked fine.

if ( !empty( $_REQUEST['action'] ) )
    do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );


If I change the admin-ajax.php code to this it works fine:

if ( !empty( $_REQUEST['action'] ) ) {

    do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );

} else {



I'm a total loss as to what is causing this to happen.

Perhaps there is something else in the script that is blocking no-logged in user access, but I can't see it.

share|improve this question
Just a guess: Did you change the line endings? Maybe during the transfer of this file to the server? – toscho Jun 11 '12 at 13:47
Does your actual AJAX callback end with a call to die()? If your code doesn't, then WordPress will fire the action hook as expected and still call die('-1') afterwards. – EAMann Jun 11 '12 at 13:57
up vote 4 down vote accepted

You should end all "async" functions with die() or exit, otherwise WordPress does it for you returning -1.

share|improve this answer
At the bottom of the callback I had return *database query". So I removed the return from the beginning of the database query and put die() at the end and it works fine now. Thanks for all your responses. – AndyW Jun 11 '12 at 14:46

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.