Last active
June 16, 2016 08:02
-
-
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
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
<?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