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'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
jQuery.ajax({
    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?

share|improve this question
    
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 Apr 9 '13 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). –  dalbaeb Apr 9 '13 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 Apr 9 '13 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 Apr 9 '13 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 Apr 9 '13 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' ) );
share|improve this answer
    
Hey Andrew, no one will be using this without privileges, so I don't have that call. –  skustes Apr 9 '13 at 12:58

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.