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'])) {
refresh_my_plugin();
}
function refresh_my_plugin() {
// main function, runs daily with cron
return true;
}
?>
<button id='refresh'>Refresh My Plugin</button>
<script>
jQuery('#refresh').click(function(){
$.ajax({
type: 'post',
data: { "refresh_my_plugin": "now"},
success: function(response) {
jQuery('#refresh').text("Successfully Refreshed!");
},
error: function(response) {
jQuery('#refresh').text("...error!");
},
});
});
</script>