Skip to content

Instantly share code, notes, and snippets.

@davidsword
Last active February 3, 2018 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidsword/a92239204229686a5b31cf13100054bc to your computer and use it in GitHub Desktop.
Save davidsword/a92239204229686a5b31cf13100054bc to your computer and use it in GitHub Desktop.
<?
add_action('wp', 'myplugin_schedule_cron');
add_action('myplugin_cronjob', 'myplugin_cron_function');
#add_action('wp_head', 'myplugin_cron_function'); //test
/*-------------------------------------------------------------
Name: myplugin_schedule_cron
Purpose: schedule cron on page load if not scheduled
Receive: - none -
Return: - none -
-------------------------------------------------------------*/
function myplugin_schedule_cron() {
if ( !wp_next_scheduled( 'myplugin_cronjob' ) )
wp_schedule_event(time(), 'daily', 'myplugin_cronjob');
}
/*-------------------------------------------------------------
Name: myplugin_cron_function
Purpose: function to run with cron
Receive: - none -
Return: - none -
-------------------------------------------------------------*/
function myplugin_cron_function() {
//do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment