Skip to content

Instantly share code, notes, and snippets.

@alanpilloud
Last active June 16, 2016 08:02
Show Gist options
  • Save alanpilloud/6d3dad83b02a61ba8f46c20a547e85a3 to your computer and use it in GitHub Desktop.
Save alanpilloud/6d3dad83b02a61ba8f46c20a547e85a3 to your computer and use it in GitHub Desktop.
This is how I add a cron action in a WordPress Plugin #wp
<?php
/*
Plugin Name: My Cronjobs
*/
defined('ABSPATH') or die;
/**
* Add Cron when the theme is activated
*/
register_activation_hook(__FILE__, function () {
wp_schedule_event(time(), 'hourly', 'my_hourly_event');
});
/**
* Cron action
*/
add_action('my_hourly_event', function () {
});
/**
* Remove Cron when the theme is deactivated
*/
register_deactivation_hook(__FILE__, function () {
wp_clear_scheduled_hook('my_hourly_event');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment