diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 7b6c30afe4..a707af89c8 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -2317,4 +2317,71 @@ function get_num_queries() { return $wpdb->num_queries; } +function wp_schedule_event($timestamp, $recurrence, $hook) { + $args = array_slice(func_get_args(), 3); + $crons = get_option('cron'); + $crons[$timestamp][$hook] = array('recur' => $recurrence, 'args' => $args); + ksort($crons); + update_option('cron', $crons); +} + +function wp_unschedule_event($timestamp, $hook) { + $crons = get_option('cron'); + unset($crons[$timestamp][$hook]); + if ( empty($crons[$timestamp]) ) + unset($crons[$timestamp]); + update_option('cron', $crons); +} + +function wp_clear_scheduled_hook($hook) { + while($timestamp = next_scheduled('scheduled_hook')) + wp_unschedule_event($timestamp, 'scheduled_hook'); +} + +function next_scheduled($hook) { + $crons = get_option('cron'); + if ( empty($crons) ) + return false; + foreach($crons as $timestamp => $cron) { + //if($timestamp <= time()) continue; + if(isset($cron[$hook])) return $timestamp; + } + return false; +} + +function spawn_cron() { + if (array_shift(array_keys(get_option('cron'))) > time()) return; + + $cron_url = get_settings('siteurl') . '/wp-cron.php'; + $parts = parse_url($cron_url); + $argyle = @ fsockopen($parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01); + if ( $argyle ) + fputs($argyle, "GET {$parts['path']}?time=" . time() . '&check=' + . md5(DB_PASS . '187425') . " HTTP/1.0\r\nHost: {$_SERVER['HTTP_HOST']}\r\n\r\n"); +} + +function wp_cron() { + if (array_shift(array_keys(get_option('cron'))) > time()) + return; + + $crons = get_option('cron'); + $newcrons = $crons; + foreach ($crons as $timestamp => $cronhooks) { + if ($timestamp > time()) break; + foreach($cronhooks as $hook => $args) { + do_action($hook, $args['args']); + $recurrence = $args['recur']; + if ( 'hourly' == $recurrence ) { + $args = array_merge( array($timestamp + 3600, $recurrence, $hook), $args['args']); + call_user_func_array('wp_schedule_event', $args); + } else if ( 'daily' == $recurrence ) { + $args = array_merge( array($timestamp + 86400, $recurrence, $hook), $args['args']); + call_user_func_array('wp_schedule_event', $args); + } + + wp_unschedule_event($timestamp, $hook); + } + } +} + ?>