Skip to content

Instantly share code, notes, and snippets.

@MikeNGarrett
Created January 27, 2014 20:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeNGarrett/8656808 to your computer and use it in GitHub Desktop.
Save MikeNGarrett/8656808 to your computer and use it in GitHub Desktop.
Simple WordPress Scheduled Task Structure
<?php
add_action( 'wp', 'schedule_task' );
/* Let's schedule some tasks! */
function schedule_task() {
if ( ! wp_next_scheduled( 'task_hook' ) ) {
// Add scheduled daily task
wp_schedule_event( time(), 'daily', 'task_hook');
}
}
add_action( 'task_hook', 'function_to_run' );
/* Garbage collection for transient cache in wp_options table in db */
function function_to_run() {
// Do stuff.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment