我遇到了一个问题,我已经安排了一段时间的活动,然后就停止了。查看事件队列后,我发现已计划的事件不再在队列中。
如果我停用插件,然后重新激活插件,那么时间表就会回来,并在一段时间内工作。
我不知道WordPress是否有在事件超时或类似情况下删除事件的功能。
这是我的代码:
register_activation_hook(__FILE__, \'k2_section_featured_ads_setup\');
function k2_section_featured_ads_setup() {
wp_schedule_event(\'1395871200\', \'minutely\', \'k2_section_featured_ads_hook\');
}
register_deactivation_hook(__FILE__, \'k2_section_featured_ads_deactivation\');
function k2_section_featured_ads_deactivation() {
$featured_next = wp_next_scheduled(\'k2_section_featured_ads_hook\');
wp_unschedule_event($featured_next, \'k2_section_featured_ads_hook\');
}
add_action(\'k2_section_featured_ads_hook\', \'k2_section_featured_ads_check_time\');
function k2_section_featured_ads_check_time() {
// function here
}
这是我的额外cron计划的过滤器
function k2_cron_add_schedules( $schedules ) {
$schedules[\'quarterday\'] = array(
\'interval\' => 14400,
\'display\' => __(\'Once every 4 hours\')
);
$schedules[\'minutely\'] = array(
\'interval\' => 60,
\'display\' => __(\'Once every 1 minute\')
);
return $schedules;
}
add_filter(\'cron_schedules\', \'k2_cron_add_schedules\');