Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created April 13, 2014 13:36
Show Gist options
  • Save tommcfarlin/55c53c8189ed7d439407 to your computer and use it in GitHub Desktop.
Save tommcfarlin/55c53c8189ed7d439407 to your computer and use it in GitHub Desktop.
[WordPress] Define a custom schedule for cron jobs to run within the context of WordPress.
<?php
add_filter( 'cron_schedules', 'acme_add_weekly_cron_schedule' );
/**
* Adds a weekly interval to the WordPress scheduled tasks.
*
* Accepts an array of schedules that WordPress current defines for its
* scheduled tasks, and introduces a new weekly interval that can be used
* via the API.
*
* The interval is defined by using a week (in terms of seconds) and will be
* displayed as 'Once Daily' in the dashboard (when using a cron viewer) such
* as Cron View (https://wordpress.org/plugins/cron-view/).
*
* @param array $schedules The array of schedules that WordPress provides.
* @return array The updated schedules with the weekly interval defined.
*/
function acme_add_weekly_cron_schedule( $schedules ) {
$schedules['weekly'] = array(
'interval' => 604800,
'display' => 'Once Weekly'
);
return $schedules;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment