diff --git a/lib/cron.php b/lib/cron.php index 0ab14230fab3f0fde975667f0fad5ff04a052d2f..b5a76ff92fe4263b3ee8fac443364b0841903165 100644 --- a/lib/cron.php +++ b/lib/cron.php @@ -1,33 +1,32 @@ <?php - // Run cron jobs for the current blog. // (Use switch_to_blog() before calling this). function noblogs_run_cron_for_current_blog() { - $crons = _get_cron_array(); - if ($crons === false) { - return; - } - - $local_time = time(); + $crons = wp_get_ready_cron_jobs(); foreach ($crons as $timestamp => $cronhooks) { - if ($timestamp > $local_time) - continue; foreach ($cronhooks as $hook => $keys) { foreach ($keys as $k => $v) { $args_str = implode(', ', $v['args']); echo " {$k} -> {$hook} ({$args_str})\n"; $schedule = $v['schedule']; - if ($schedule != false) { - $new_args = array($timestamp, $schedule, $hook, $v['args']); - call_user_func_array('wp_reschedule_event', $new_args); + if ($schedule) { + $result = wp_reschedule_event($timestamp, $schedule, $hook, $v['args'], true); + if (is_wp_error($result)) { + error_log('cron reschedule event error for hook: %1$s, code: %2$s, message: %3$s, data: %4%s', + $hook, $result->get_error_code(), $result->get_error_message(), wp_json_encode($v)); + do_action('cron_reschedule_event_error', $result, $hook, $v); + } + } + $result = wp_unschedule_event($timestamp, $hook, $v['args'], true); + if (is_wp_error($result)) { + error_log('cron unschedule event error for hook: %1$s, code: %2$s, message: %3$s, data: %4%s', + $hook, $result->get_error_code(), $result->get_error_message(), wp_json_encode($v)); + do_action('cron_unschedule_event_error', $result, $hook, $v); } - wp_unschedule_event($timestamp, $hook, $v['args']); do_action_ref_array($hook, $v['args']); } } } } - -