WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 currently developing a plugin that uses ajax functionality.

Problem: The callback isn't fired = no data gets processed.

if ( ! is_admin() )
    add_action( 'after_setup_theme', array( 'wpseAjaxClass', 'init' ), 10 );
share|improve this question
Last time I had this issue was due to the callback function not actually being accessible during the AJAX request. For example, I buried the call to instantiate the class under a function like is_single(). It was called when the page was being viewed, but not when the AJAX request was made. I see that one of your comments says the code is part of the class. Any chance you can show the rest of the class? – tollmanz Feb 6 '12 at 5:17
@tollmanz Thanks for the comment. jQuery mobile loads everything with one request, so basically it's like a js-slider/-carousel. The my_action_cb() fn itself isn't hidden behind something. Just sits right in the middle of the class. As shown in the, the enqueue happens right in the __construct() of the class. I added a screenshot from the console. Please see Edit. Any other ideas? – kaiser Feb 6 '12 at 5:44
Sorry to harp on this, but clearly the script cannot find the function. How is the class itself instantiated? When I have these issues, it's usually something little that I've missed. I'd love to look over the code to see if I could spot something. – tollmanz Feb 6 '12 at 5:58
Ok :) Here's a pastebin. Tell me if the link isn't working. (And thanks for taking the time). – kaiser Feb 6 '12 at 6:00
To be more clear, I created this revised pastebin based on your pastebin: pastebin.com/r0Ud14aB – tollmanz Feb 6 '12 at 6:11
up vote 2 down vote accepted

The answer was as stupid as simple: I wrapped the init for the class in a ! is_admin() call. This successfully prevented the callback from beeing fired.

Rule for AJAX loading

  • Load it in public
  • Don't hide it behind a ! is_admin() call.

The 2nd line from admin-ajax.php

define( 'WP_ADMIN', true );
share|improve this answer
I knew it was going to be something like this. Whenever I get the dreaded "0" response with WP AJAX, I instantly think that my function is inaccessible! Congrats on finding the issue and getting your life back ;) – tollmanz Feb 7 '12 at 3:43
:) Thanks for this comment. I'm currently more than angry about this issue and writing on wp-hackers :P – kaiser Feb 7 '12 at 3:48

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.