Skip to content

Instantly share code, notes, and snippets.

@fahidjavid
Created August 25, 2014 07:33
Show Gist options
  • Save fahidjavid/0507d425114ccd462843 to your computer and use it in GitHub Desktop.
Save fahidjavid/0507d425114ccd462843 to your computer and use it in GitHub Desktop.
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__, 'prefix_activation' );
/**
* On activation, set a time, frequency and name of an action hook to be scheduled.
*/
function prefix_activation() {
wp_schedule_event( time(), 'hourly', 'prefix_hourly_event_hook' );
}
add_action( 'prefix_hourly_event_hook', 'prefix_do_this_hourly' );
/**
* On the scheduled action hook, run the function.
*/
function prefix_do_this_hourly() {
// do something every hour
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment