Codex tools: Log in
Contents |
Schedules a hook which will be executed by the WordPress actions core on a specific interval, specified by you. The action will trigger when someone visits your WordPress site, if the scheduled time has passed. See the Plugin API for a list of hooks.
<?php wp_schedule_event($timestamp, $recurrence, $hook, $args); ?>
To schedule an hourly event in a plugin, call wp_schedule_event on activation (otherwise you will end up with a lot of scheduled events!):
register_activation_hook(__FILE__, 'my_activation');
add_action('my_hourly_event', 'do_this_hourly');
function my_activation() {
wp_schedule_event( time(), 'hourly', 'my_hourly_event');
}
function do_this_hourly() {
// do something every hour
}
Don't forget to clean the scheduler on deactivation:
register_deactivation_hook(__FILE__, 'my_deactivation');
function my_deactivation() {
wp_clear_scheduled_hook('my_hourly_event');
}
This example doesn't rely on plugin activation (via the plugins directory) rather it simply adds the event if it is missing.
add_action('my_hourly_event', 'do_this_hourly');
function my_activation() {
if ( !wp_next_scheduled( 'my_hourly_event' ) ) {
wp_schedule_event( time(), 'hourly', 'my_hourly_event');
}
}
add_action('wp', 'my_activation');
function do_this_hourly() {
// do something every hour
}
Since: 2.1.0
wp_schedule_event() is located in wp-includes/cron.php
For a comprehensive list of functions, take a look at the category Functions
Also, see Function_Reference