I'm developing a plugin and I've started from WPPB and Wordpress 4.3.1. I've named it dogmaweb. I need to submit a form to the plugin via Ajax. The form is created by the plugin itself. In my class-dogmaweb.php I'm trying to add the action that processes the form data server side, and here is what I've come up with, until now:
public function enqueue_scripts()
{
$script_handle = 'userprofilesumbit';
add_action( 'wp_ajax_'.$script_handle, array($this, 'userprofileform_process') );
add_action( 'wp_ajax_nopriv_'.$script_handle, array($this, 'userprofileform_process') );
wp_register_script( $script_handle, plugins_url() . '/public/js/dogmaweb-public.js' );
$userprofilesumbit_data = array('ajax_url' => admin_url( 'admin-ajax.php' ), 'form_action' => $script_handle, 'form_id' => '#'.Dogmaweb::$userprofileform_id);
wp_localize_script($script_handle, 'submit_params', $userprofilesumbit_data);
wp_enqueue_script($script_handle);
}
The symptom of the problem is that admin-ajax.php is not calling my function and it is returning 0. I've stepped through the wordpress code to understand why (I'm using Netbeans and xdebug). The problem is that these lines of code in plugin.php do not find the $tag
in the $wp_filter
array. The $tag
variable at that point contains "wp_ajax_userprofilesumbit"
, which is exactly what I specified for the $hook
argument to the add_action function (I've used the same $script_handle
variable as you can see in my code).
I've also stepped through the add_action
code and I'm sure the global $wp_filter
array does contain "wp_ajax_userprofilesumbit"
key when add_action
returns after I call it. However I'm also sure that it does not contain that key anymore when plugin.php executes (called by admin-ajax.php).
Why is my filter being removed from $wp_filter
? What am I doing wrong?