| ... | ... |
@@ -8,4 +8,24 @@ |
| 8 | 8 |
*/ |
| 9 | 9 |
|
| 10 | 10 |
|
| 11 |
+add_action('wp_ajax_callme', 'callme_func');
|
|
| 12 |
+add_action('wp_ajax_nopriv_callme', 'callme_func');
|
|
| 13 |
+ |
|
| 14 |
+function callme_func() {
|
|
| 15 |
+ echo "hello, world"; |
|
| 16 |
+ wp_die(); |
|
| 17 |
+} |
|
| 18 |
+ |
|
| 19 |
+add_action ('wp_enqueue_scripts', 'enqueue_ajax_script');
|
|
| 20 |
+ |
|
| 21 |
+function enqueue_ajax_script() {
|
|
| 22 |
+ $path = plugins_url() . "/". basename(dirname(__FILE__)) . "/"; |
|
| 23 |
+ |
|
| 24 |
+ wp_enqueue_script('jquery');
|
|
| 25 |
+ wp_enqueue_script('ajax', $path . 'ajax.js' );
|
|
| 26 |
+ |
|
| 27 |
+ wp_localize_script( 'ajax', 'ajax_object', |
|
| 28 |
+ array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'we_value' => 1234 ) ); |
|
| 29 |
+} |
|
| 30 |
+ |
|
| 11 | 31 |
?> |