I found this plugin to create plugin.
I got an issue, how do I make an ajax call? As the docs, I've created plugin-name/includes/class-admin-ajax.php
and placed my wp_ajax_
hook there, but seems like the hook is not recognized yet.
class-admin-ajax.php
<?php
add_action('wp_ajax_test', 'test');
function test(){ die('yay'); }
javascript section
<script>
jQuery(document).ready(function ($) {
$('#submit').click(function () {
var url = ajaxurl + "?action=test";
$.get( url, function () {
});
})
})
</script>
The ajax call always return 0. Seems like the wp_ajax_test
is not registered yet. Can you point out where are my mistakes?