Update
I got it to fire using the following curl command:
curl -H "Accept: application/json" -X POST http://localhost/wordpress/wp-admin/admin-ajax.php -d "action=vixo_wordpress_signon&data=banjometer" --trace -
Not really sure how to work out to get it to accept json, but hey...
Original Question
I am new to WordPress and I am having problems getting Ajax to work - but I am also having problems understanding how WordPress loads PHP.
I have a plugin file:
/usr/share/wordpress/wp-content/plugins/myplugin.php
It has the following code in it:
// set up the ajax calls
add_action('wp_ajax_my_ajax', 'my_ajax');
add_action('wp_ajax_nopriv_my_ajax', 'my_ajax');
function my_ajax () {
debug_log ("My ajax fired...");
echo "banjolalia...";
die ();
}
I want to demonstrate that the ajax has fired using Curl:
curl -X POST http://localhost/wordpress/wp-admin/admin-ajax.php -d '{"action":"my_ajax","data":"banjometer"}' --trace -
(The home page is at http://localhost/wordpress)
I am expecting to see curl return banjolalia and a line appear in the debug log.
What I see is the function returns 0
The Ajax is standalone because I am writing single-signon code and I need the child service to query WordPress and see if the user is logged in.
Because I am new to WordPress/PHP I do not have a robust development cycle.
The way I have been (trying) to get the code to reload is by Deactivating/Activating the plugin on the Admin page. This doesn't seem to work. I wasn't sure if my changes were loading into WordPress so I actually switched the lappie off and on again - but still the Ajax didnt' fire.
I have 2 debugging Plugins installed:
- Debug-Bar
- Debug-Console-Bar
The problems I have from a Dev perspective are:
- how can I use the PHP console to check what code is loaded/force a reload?
- how can I use the PHP console to see what actions are registed on what hooks?