Created
October 3, 2012 15:30
-
-
Save garyc40/3827580 to your computer and use it in GitHub Desktop.
WordPress AJAX & Nonces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// embed the javascript file that makes the AJAX request | |
wp_enqueue_script( 'my-ajax-request', plugin_dir_url( __FILE__ ) . 'js/ajax.js', array( 'jquery' ) ); | |
wp_localize_script( 'my-ajax-request', 'MyAjax', array( | |
// URL to wp-admin/admin-ajax.php to process the request | |
'ajaxurl' => admin_url( 'admin-ajax.php' ), | |
// generate a nonce with a unique ID "myajax-post-comment-nonce" | |
// so that you can check it later when an AJAX request is sent | |
'postCommentNonce' => wp_create_nonce( 'myajax-post-comment-nonce' ), | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment