Created
January 27, 2014 20:37
-
-
Save MikeNGarrett/8656808 to your computer and use it in GitHub Desktop.
Simple WordPress Scheduled Task Structure
This file contains hidden or 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 | |
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