Skip to content

Instantly share code, notes, and snippets.

@tomfinitely
Created September 18, 2015 14:35
Show Gist options
  • Save tomfinitely/201c5824a1706c5fbc98 to your computer and use it in GitHub Desktop.
Save tomfinitely/201c5824a1706c5fbc98 to your computer and use it in GitHub Desktop.
WP Cron Intervals
<?php
// Add a new interval of a week
// See http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
add_filter( 'cron_schedules', 'myprefix_add_weekly_cron_schedule' );
function myprefix_add_weekly_cron_schedule( $schedules ) {
$schedules['weekly'] = array(
'interval' => 604800, // 1 week in seconds
'display' => __( 'Once Weekly' ),
);
return $schedules;
}
// Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'myprefix_my_cron_action' ) ) {
wp_schedule_event( time(), 'weekly', 'myprefix_my_cron_action' );
}
// Hook into that action that'll fire weekly
add_action( 'myprefix_my_cron_action', 'myprefix_function_to_run' );
function myprefix_function_to_run() {
// Add some code here
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment