3 function wp_schedule_single_event( $timestamp, $hook, $args = array()) {
4 $crons = _get_cron_array();
5 $key = md5(serialize($args));
6 $crons[$timestamp][$hook][$key] = array( 'schedule' => false, 'args' => $args );
7 uksort( $crons, "strnatcasecmp" );
8 _set_cron_array( $crons );
11 function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array()) {
12 $crons = _get_cron_array();
13 $schedules = wp_get_schedules();
14 $key = md5(serialize($args));
15 if ( !isset( $schedules[$recurrence] ) )
17 $crons[$timestamp][$hook][$key] = array( 'schedule' => $recurrence, 'args' => $args, 'interval' => $schedules[$recurrence]['interval'] );
18 uksort( $crons, "strnatcasecmp" );
19 _set_cron_array( $crons );
22 function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array()) {
23 $crons = _get_cron_array();
24 $schedules = wp_get_schedules();
25 $key = md5(serialize($args));
28 // First we try to get it from the schedule
30 $interval = $schedules[$recurrence]['interval'];
31 // Now we try to get it from the saved interval in case the schedule disappears
33 $interval = $crons[$timestamp][$hook][$key]['interval'];
34 // Now we assume something is wrong and fail to schedule
38 while ( $timestamp < time() + 1 )
39 $timestamp += $interval;
41 wp_schedule_event( $timestamp, $recurrence, $hook, $args );
44 function wp_unschedule_event( $timestamp, $hook, $args = array() ) {
45 $crons = _get_cron_array();
46 $key = md5(serialize($args));
47 unset( $crons[$timestamp][$hook][$key] );
48 if ( empty($crons[$timestamp][$hook]) )
49 unset( $crons[$timestamp][$hook] );
50 if ( empty($crons[$timestamp]) )
51 unset( $crons[$timestamp] );
52 _set_cron_array( $crons );
55 function wp_clear_scheduled_hook( $hook ) {
56 $args = array_slice( func_get_args(), 1 );
58 while ( $timestamp = wp_next_scheduled( $hook, $args ) )
59 wp_unschedule_event( $timestamp, $hook, $args );
62 function wp_next_scheduled( $hook, $args = array() ) {
63 $crons = _get_cron_array();
64 $key = md5(serialize($args));
67 foreach ( $crons as $timestamp => $cron ) {
68 if ( isset( $cron[$hook][$key] ) )
74 function spawn_cron() {
75 $crons = _get_cron_array();
77 if ( !is_array($crons) )
80 $keys = array_keys( $crons );
81 if ( array_shift( $keys ) > time() )
84 $cron_url = get_option( 'siteurl' ) . '/wp-cron.php';
85 $parts = parse_url( $cron_url );
87 if ($parts['scheme'] == 'https') {
88 // support for SSL was added in 4.3.0
89 if (version_compare(phpversion(), '4.3.0', '>=') && function_exists('openssl_open')) {
90 $port = isset($parts['port']) ? $parts['port'] : 443;
91 $argyle = @fsockopen('ssl://' . $parts['host'], $port, $errno, $errstr, 0.01);
96 $port = isset($parts['port']) ? $parts['port'] : 80;
97 $argyle = @ fsockopen( $parts['host'], $port, $errno, $errstr, 0.01 );
102 "GET {$parts['path']}?check=" . wp_hash('187425') . " HTTP/1.0\r\n"
103 . "Host: {$_SERVER['HTTP_HOST']}\r\n\r\n"
108 // Prevent infinite loops caused by lack of wp-cron.php
109 if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false )
112 $crons = _get_cron_array();
114 if ( !is_array($crons) )
117 $keys = array_keys( $crons );
118 if ( isset($keys[0]) && $keys[0] > time() )
121 $schedules = wp_get_schedules();
122 foreach ( $crons as $timestamp => $cronhooks ) {
123 if ( $timestamp > time() ) break;
124 foreach ( $cronhooks as $hook => $args ) {
125 if ( isset($schedules[$hook]['callback']) && !call_user_func( $schedules[$hook]['callback'] ) )
133 function wp_get_schedules() {
135 'hourly' => array( 'interval' => 3600, 'display' => __('Once Hourly') ),
136 'daily' => array( 'interval' => 86400, 'display' => __('Once Daily') ),
138 return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
141 function wp_get_schedule($hook, $args = array()) {
142 $crons = _get_cron_array();
143 $key = md5(serialize($args));
146 foreach ( $crons as $timestamp => $cron ) {
147 if ( isset( $cron[$hook][$key] ) )
148 return $cron[$hook][$key]['schedule'];
157 function _get_cron_array() {
158 $cron = get_option('cron');
159 if ( ! is_array($cron) )
162 if ( !isset($cron['version']) )
163 $cron = _upgrade_cron_array($cron);
165 unset($cron['version']);
170 function _set_cron_array($cron) {
171 $cron['version'] = 2;
172 update_option( 'cron', $cron );
175 function _upgrade_cron_array($cron) {
176 if ( isset($cron['version']) && 2 == $cron['version'])
181 foreach ($cron as $timestamp => $hooks) {
182 foreach ( $hooks as $hook => $args ) {
183 $key = md5(serialize($args['args']));
184 $new_cron[$timestamp][$hook][$key] = $args;
188 $new_cron['version'] = 2;
189 update_option( 'cron', $new_cron );