The get_schedule WordPress PHP filter is used to modify the schedule name for a specified hook.
Usage
add_filter('get_schedule', 'your_custom_function', 10, 3);
function your_custom_function($schedule, $hook, $args) {
// your custom code here
return $schedule;
}
Parameters
$schedule(string|false) – The schedule for the hook. Returns false if not found.$hook(string) – The action hook to execute when cron is run.$args(array) – The arguments to pass to the hook’s callback function.
More information
See WordPress Developer Resources: get_schedule
Examples
Change schedule for a specific hook
Modify the schedule for the my_custom_hook to run every hour.
add_filter('get_schedule', 'change_my_custom_hook_schedule', 10, 3);
function change_my_custom_hook_schedule($schedule, $hook, $args) {
if ('my_custom_hook' == $hook) {
$schedule = 'hourly';
}
return $schedule;
}
Modify schedule based on arguments
Change the schedule for my_custom_hook only if the argument my_key is set to value.
add_filter('get_schedule', 'modify_schedule_based_on_args', 10, 3);
function modify_schedule_based_on_args($schedule, $hook, $args) {
if ('my_custom_hook' == $hook && isset($args['my_key']) && 'value' == $args['my_key']) {
$schedule = 'daily';
}
return $schedule;
}
Return false if a specific hook is found
Prevent the unwanted_hook from running by returning false.
add_filter('get_schedule', 'disable_unwanted_hook', 10, 3);
function disable_unwanted_hook($schedule, $hook, $args) {
if ('unwanted_hook' == $hook) {
return false;
}
return $schedule;
}
Change schedule for all hooks
Modify the schedule for all hooks to run daily.
add_filter('get_schedule', 'change_all_hooks_schedule', 10, 3);
function change_all_hooks_schedule($schedule, $hook, $args) {
return 'daily';
}
Log scheduled hook information
Log the scheduled hook information to the debug.log file.
add_filter('get_schedule', 'log_scheduled_hook_info', 10, 3);
function log_scheduled_hook_info($schedule, $hook, $args) {
error_log("Hook: {$hook}, Schedule: {$schedule}, Args: " . print_r($args, true));
return $schedule;
}