#30858 closed defect (bug) (invalid)
Scheduled cron job with custom interval is unset on next cron event
Reported by: | mrtphoto | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.1 |
Component: | Cron API | Keywords: | |
Focuses: | Cc: |
Description
plugin adds new interval
function execution_schedule( $schedules ) { // adds 2min schedule interval for all import execution script $schedules['twomin'] = array( 'interval' => 120, 'display' => __('Two Minutes') ); return $schedules; } add_filter( 'cron_schedules', 'execution_schedule' ); }
on save options for plugin cron url, we clear the old hook and set the new cron job with custom interval
wp_clear_scheduled_hook( 'syt_trigger_one' ); wp_clear_scheduled_hook( 'syt_execution_one' ); wp_schedule_event(current_time( 'timestamp' ),'twicedaily','syt_trigger_one'); wp_schedule_event(current_time( 'timestamp' ),'twomin','syt_execution_one');
on options page I display the schedule for the hook
echo wp_get_schedule( 'syt_execution_one' );
Immediately after saving it displays 'twomin'. When loading the options page after that it shows nothing .
An output of
print_r(get_option('cron'));
confirms the existence of the scheduled cron event on save and subsequent disappearance of the hook from cron
[1419832800] => Array ( [syt_trigger_one] => Array ( [40cd750bba9870f18aada2478b24840a] => Array ( [schedule] => twicedaily [args] => Array ( ) [interval] => 43200 ) ) [syt_execution_one] => Array ( [40cd750bba9870f18aada2478b24840a] => Array ( [schedule] => twomin [args] => Array ( ) [interval] => 120 ) ) )
..after loading the options page again, no "syt_execution_one" hook:
[1419832800] => Array ( [syt_trigger_one] => Array ( [40cd750bba9870f18aada2478b24840a] => Array ( [schedule] => twicedaily [args] => Array ( ) [interval] => 43200 ) ) )
Change History (3)
#2
@
10 years ago
- Resolution set to invalid
- Status changed from new to closed
I was doing some cleanup work on the plugin to share it for troubleshooting and found that my addition to the cron_schedules filter ended up inside the hook for admin_init. So, on the options page is was working. But when wp-cron ran "twomin" was no longer a valid interval and was removed.
I moved it outside admin_init and it works fine now. I'm going to assume that the removal of the cron job with an invalid interval is a feature.
Could you turn the code you supplied above into a basic plugin that reproduces the issue?