How to add WordPress nonces to ajax request

I have a plugin, a cron job runs refresh_my_plugin() daily. I need a button on my plugins Settings/option page, allowing a user to manually run said function, and I want it inline, with ajax. I’ve got the following, which should work – but how would I add WordPress Nonces to it? <?php if (isset($_POST[‘refresh_my_plugin’])) { … Read more

Using nonce external of WP Admin

All, I’ve got two wordpress pages. One wordpress page displays a form to do some registration stuff for the website. The second wordpress page actually processes the data and inserts it into a custom MySQL table that I have. I’d like to use the nonce functionality inherit to WordPress. The user doesn’t have to be … Read more

Handling nonces for actions from guests to logged-in users

Imagine the following scenario: John has an account on my website, but is currently not logged in. He clicks the “upvote” button on an article, but is redirected to the login page because only logged-in users can upvote. In the referral URL (to which John is redirected after login) the following parameters are passed: action=upvote … Read more

Fatal error: Call to undefined function wp_create_nonce()

I’m trying to add a nonce to my plugin’s Ajax. I’m not sure why I’m getting this error: Fatal error: Call to undefined function wp_create_nonce() In my php file : wp_localize_script(‘my-ajax-handle’, ‘the_ajax_script’, array(‘ajaxurl’=> admin_url(‘admin-ajax.php’), ‘my_nonce’ => wp_create_nonce(‘myajax-nonce’))); In js file: jQuery.post(the_ajax_script.ajaxurl, {my_nonce : the_ajax_script.my_nonce}, jQuery(“#theForm”).serialize() + “&maxLat=”+ map_bounds[0] + “&maxLong=”+ map_bounds[1] + “&minLat=”+ map_bounds[2] + … Read more