在我看来,只有在尚未计划此类事件“send\\u email\\u alerts\\u hook”时,您才添加此事件。试试这样的方法,如果有效,请告诉我。
function shedule_email_alerts() {
if ( !wp_next_scheduled( \'send_email_alerts_hook\' ) ) {
wp_schedule_event(time(), \'daily\', \'send_email_alerts_hook\');
} else {
wp_reschedule_event(time(), \'daily\', \'send_email_alerts_hook\');
}
}
问题是,您将一直“重写”此事件,因此最好在第一次运行此函数时停用它。
最好的解决方案是检查这些作业是如何收集的,并检查是否已添加此事件。如果是,则检查重复性是否不同-如果是,则重新安排。您可以在wp includes/cron中找到此函数。php行~ 63
function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array()) {
$crons = _get_cron_array();
$schedules = wp_get_schedules();
if ( !isset( $schedules[$recurrence] ) )
return false;
$event = (object) array( \'hook\' => $hook, \'timestamp\' => $timestamp, \'schedule\' => $recurrence, \'args\' => $args, \'interval\' => $schedules[$recurrence][\'interval\'] );
$event = apply_filters(\'schedule_event\', $event);
// A plugin disallowed this event
if ( ! $event )
return false;
$key = md5(serialize($event->args));
$crons[$event->timestamp][$event->hook][$key] = array( \'schedule\' => $event->schedule, \'args\' => $event->args, \'interval\' => $event->interval );
uksort( $crons, "strnatcasecmp" );
_set_cron_array( $crons );
}
祝你好运!