I've been working on a class for my free plugins that outputs a "Donate" form. The "No thanks" dismissal link hides the form and runs an AJAX call to update a WP Option keeping track of the dismissal.

I'm having issues getting the called PHP function to actually fire. I added the "success" function to output an echo that I added to the PHP function called by the AJAX (typically, the function has no output, only a WP Option update), but "data" is always 0 and nothing happens in the database.

I'm guessing that WP isn't actually able to use the function for some reason. The function is declared as public and this has actually worked. I'm not sure which modifications I made could've broken it.

Here's the pertinent part of my jQuery AJAX call

// Create the AJAX data
ajax_call_data = {
    'action': 'dismiss_ppd_dmgr',
    'nonce': $nonce

// Call the AJAX function to update the options
    url: ajaxurl,
    type: 'post',
    data: ajax_call_data,
    success: function(data) { alert( data ) }

In the class, I have an attribute ajax_call, which is set at class instantiation and I'm adding my call to Wordpress like so. I've verified that $this->ajax_call is populated properly and also tried hardcoding it, instead of using the variable.

add_action( 'wp_ajax_' . $this->ajax_call , array( &$this , 'dismiss_form' ) );

So I suppose the question is, how do I debug this to figure out why WP can't call my PHP class function? Any ideas on why the function can't be found/run?

  • Check this: wordpress.stackexchange.com/q/5638/12615. But the technique is quite old... There are better and more recent examples in the archives.
    – brasofilo
    Commented Apr 9, 2013 at 0:18
  • Where's your add_action call located? Mine's usually in plugin constructor. I assume the first param that goes into add_action populates to wp_ajax_dismiss_ppd_dmgr. Also I usually just pass the $this into the second param array (without the & sign). Commented Apr 9, 2013 at 0:27
  • dalbaeb, I have it in the constructor. It does populate to wp_ajax_dismiss_ppd_dmgr...sorry, I meant to mention that. I tried removing the &, but still no dice.
    – skustes
    Commented Apr 9, 2013 at 13:07
  • brasofilo, Thanks...I'll keep scouring the archives. Still can't figure out why this thing won't run my function. Hardcoded, with variable, nothing seems to work.
    – skustes
    Commented Apr 9, 2013 at 13:08
  • The Google Machine isn't helping me find out if there's a way to get a readout of wp_ajax calls that are registered. Anyone know if there is?
    – skustes
    Commented Apr 9, 2013 at 17:53

1 Answer 1


Sorry don't have enough rep to just comment yet.. do you have a second add_action for no_priv?

add_action( 'wp_ajax_nopriv' . $this->ajax_call , array( &$this , 'dismiss_form' ) );
  • Hey Andrew, no one will be using this without privileges, so I don't have that call.
    – skustes
    Commented Apr 9, 2013 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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