Changes from branches/4.0/src/wp-includes/cron.php at r42343 to branches/4.9/src/wp-includes/cron.php at r42343
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.9/src/wp-includes/cron.php
r42343 r42343 1 1 <?php 2 2 /** 3 * WordPress C RONAPI3 * WordPress Cron API 4 4 * 5 5 * @package WordPress … … 7 7 8 8 /** 9 * Schedules a hookto run only once.10 * 11 * Schedules a hook which will be executedonce by the WordPress actions core at9 * Schedules an event to run only once. 10 * 11 * Schedules an event which will execute once by the WordPress actions core at 12 12 * a time which you specify. The action will fire off when someone visits your 13 13 * WordPress site, if the schedule time has passed. 14 14 * 15 * @since 2.1.0 16 * @link http://codex.wordpress.org/Function_Reference/wp_schedule_single_event 17 * 18 * @param int $timestamp Timestamp for when to run the event. 19 * @param string $hook Action hook to execute when cron is run. 15 * Note that scheduling an event to occur within 10 minutes of an existing event 16 * with the same action hook will be ignored unless you pass unique `$args` values 17 * for each scheduled event. 18 * 19 * @since 2.1.0 20 * @link https://codex.wordpress.org/Function_Reference/wp_schedule_single_event 21 * 22 * @param int $timestamp Unix timestamp (UTC) for when to run the event. 23 * @param string $hook Action hook to execute when event is run. 20 24 * @param array $args Optional. Arguments to pass to the hook's callback function. 25 * @return false|void False if the event does not get scheduled. 21 26 */ 22 27 function wp_schedule_single_event( $timestamp, $hook, $args = array()) { 23 // don't schedule a duplicate if there's already an identical event due in the next 10 minutes 28 // Make sure timestamp is a positive integer 29 if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { 30 return false; 31 } 32 33 // Don't schedule a duplicate if there's already an identical event due within 10 minutes of it 24 34 $next = wp_next_scheduled($hook, $args); 25 if ( $next && $next <= $timestamp + 10 * MINUTE_IN_SECONDS ) 26 return; 35 if ( $next && abs( $next - $timestamp ) <= 10 * MINUTE_IN_SECONDS ) { 36 return false; 37 } 27 38 28 39 $crons = _get_cron_array(); 29 40 $event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'schedule' => false, 'args' => $args ); 30 41 /** 31 * Filter a single event before it is scheduled.42 * Filters a single event before it is scheduled. 32 43 * 33 44 * @since 3.1.0 34 45 * 35 * @param object $event An object containing an event's data. 46 * @param stdClass $event { 47 * An object containing an event's data. 48 * 49 * @type string $hook Action hook to execute when event is run. 50 * @type int $timestamp Unix timestamp (UTC) for when to run the event. 51 * @type string|false $schedule How often the event should recur. See `wp_get_schedules()`. 52 * @type array $args Arguments to pass to the hook's callback function. 53 * } 36 54 */ 37 55 $event = apply_filters( 'schedule_event', $event ); … … 49 67 50 68 /** 51 * Schedule a periodicevent.69 * Schedule a recurring event. 52 70 * 53 71 * Schedules a hook which will be executed by the WordPress actions core on a … … 55 73 * visits your WordPress site, if the scheduled time has passed. 56 74 * 57 * Valid values for the recurrence are hourly, daily and twicedaily. These can58 * be extended using the cron_schedulesfilter in wp_get_schedules().75 * Valid values for the recurrence are hourly, daily, and twicedaily. These can 76 * be extended using the {@see 'cron_schedules'} filter in wp_get_schedules(). 59 77 * 60 78 * Use wp_next_scheduled() to prevent duplicates … … 62 80 * @since 2.1.0 63 81 * 64 * @param int $timestamp Timestampfor when to run the event.82 * @param int $timestamp Unix timestamp (UTC) for when to run the event. 65 83 * @param string $recurrence How often the event should recur. 66 * @param string $hook Action hook to execute when cronis run.84 * @param string $hook Action hook to execute when event is run. 67 85 * @param array $args Optional. Arguments to pass to the hook's callback function. 68 * @return bool|null False on failure, null when complete with scheduling event.86 * @return false|void False if the event does not get scheduled. 69 87 */ 70 88 function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array()) { 89 // Make sure timestamp is a positive integer 90 if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { 91 return false; 92 } 93 71 94 $crons = _get_cron_array(); 72 95 $schedules = wp_get_schedules(); … … 95 118 * @since 2.1.0 96 119 * 97 * @param int $timestamp Timestampfor when to run the event.120 * @param int $timestamp Unix timestamp (UTC) for when to run the event. 98 121 * @param string $recurrence How often the event should recur. 99 * @param string $hook Action hook to execute when cronis run.122 * @param string $hook Action hook to execute when event is run. 100 123 * @param array $args Optional. Arguments to pass to the hook's callback function. 101 * @return bool|null False on failure. Null when event isrescheduled.124 * @return false|void False if the event does not get rescheduled. 102 125 */ 103 126 function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() ) { 127 // Make sure timestamp is a positive integer 128 if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { 129 return false; 130 } 131 104 132 $crons = _get_cron_array(); 105 133 $schedules = wp_get_schedules(); … … 132 160 133 161 /** 134 * Unschedule a previously scheduled cron job.135 * 136 * The $timestamp and $hook parameters are required ,so that the event can be162 * Unschedule a previously scheduled event. 163 * 164 * The $timestamp and $hook parameters are required so that the event can be 137 165 * identified. 138 166 * 139 167 * @since 2.1.0 140 168 * 141 * @param int $timestamp Timestampfor when to run the event.169 * @param int $timestamp Unix timestamp (UTC) for when to run the event. 142 170 * @param string $hook Action hook, the execution of which will be unscheduled. 143 171 * @param array $args Arguments to pass to the hook's callback function. … … 145 173 * to uniquely identify the scheduled event, so they should be the same 146 174 * as those used when originally scheduling the event. 175 * @return false|void False if the event does not get unscheduled. 147 176 */ 148 177 function wp_unschedule_event( $timestamp, $hook, $args = array() ) { 178 // Make sure timestamp is a positive integer 179 if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { 180 return false; 181 } 182 149 183 $crons = _get_cron_array(); 150 184 $key = md5(serialize($args)); … … 158 192 159 193 /** 160 * Unschedule all cron jobs attached to a specific hook.194 * Unschedules all events attached to the hook with the specified arguments. 161 195 * 162 196 * @since 2.1.0 163 197 * 164 198 * @param string $hook Action hook, the execution of which will be unscheduled. 165 * @param array $args Optional. Arguments that were to be pass to the hook's callback function.199 * @param array $args Optional. Arguments that were to be passed to the hook's callback function. 166 200 */ 167 201 function wp_clear_scheduled_hook( $hook, $args = array() ) { … … 169 203 // Previously this function took the arguments as discrete vars rather than an array like the rest of the API 170 204 if ( !is_array($args) ) { 171 _deprecated_argument( __FUNCTION__, '3.0 ', __('This argument has changed to an array to match the behavior of the other cron functions.') );205 _deprecated_argument( __FUNCTION__, '3.0.0', __('This argument has changed to an array to match the behavior of the other cron functions.') ); 172 206 $args = array_slice( func_get_args(), 1 ); 173 207 } … … 189 223 190 224 /** 191 * Retrieve the next timestamp for a cron event. 192 * 193 * @since 2.1.0 194 * 195 * @param string $hook Action hook to execute when cron is run. 225 * Unschedules all events attached to the hook. 226 * 227 * Can be useful for plugins when deactivating to clean up the cron queue. 228 * 229 * @since 4.9.0 230 * 231 * @param string $hook Action hook, the execution of which will be unscheduled. 232 */ 233 function wp_unschedule_hook( $hook ) { 234 $crons = _get_cron_array(); 235 236 foreach( $crons as $timestamp => $args ) { 237 unset( $crons[ $timestamp ][ $hook ] ); 238 239 if ( empty( $crons[ $timestamp ] ) ) { 240 unset( $crons[ $timestamp ] ); 241 } 242 } 243 244 _set_cron_array( $crons ); 245 } 246 247 /** 248 * Retrieve the next timestamp for an event. 249 * 250 * @since 2.1.0 251 * 252 * @param string $hook Action hook to execute when event is run. 196 253 * @param array $args Optional. Arguments to pass to the hook's callback function. 197 * @return bool|int The UNIXtimestamp of the next time the scheduled event will occur.254 * @return false|int The Unix timestamp of the next time the scheduled event will occur. 198 255 */ 199 256 function wp_next_scheduled( $hook, $args = array() ) { … … 210 267 211 268 /** 212 * Send request to run cron through HTTP request that doesn't halt page loading.213 * 214 * @since 2.1.0 215 * 216 * @ return null Cron could not be spawned, because it is not needed to run.269 * Sends a request to run cron through HTTP request that doesn't halt page loading. 270 * 271 * @since 2.1.0 272 * 273 * @param int $gmt_time Optional. Unix timestamp (UTC). Default 0 (current time is used). 217 274 */ 218 275 function spawn_cron( $gmt_time = 0 ) { 219 220 276 if ( ! $gmt_time ) 221 277 $gmt_time = microtime( true ); … … 225 281 226 282 /* 227 * multiple processes on multiple web servers can run this code concurrently 228 * try to make this as atomic as possible by setting doing_cron switch 229 */ 283 * Get the cron lock, which is a Unix timestamp of when the last cron was spawned 284 * and has not finished running. 285 * 286 * Multiple processes on multiple web servers can run this code concurrently, 287 * this lock attempts to make spawning as atomic as possible. 288 */ 230 289 $lock = get_transient('doing_cron'); 231 290 … … 246 305 return; 247 306 248 if ( defined( 'ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON ) {249 if ( !empty($_POST) || defined('DOING_AJAX') )307 if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) { 308 if ( 'GET' !== $_SERVER['REQUEST_METHOD'] || defined( 'DOING_AJAX' ) || defined( 'XMLRPC_REQUEST' ) ) { 250 309 return; 310 } 251 311 252 312 $doing_wp_cron = sprintf( '%.22F', $gmt_time ); … … 265 325 } 266 326 327 // Set the cron lock with the current unix timestamp, when the cron is being spawned. 267 328 $doing_wp_cron = sprintf( '%.22F', $gmt_time ); 268 329 set_transient( 'doing_cron', $doing_wp_cron ); 269 330 270 331 /** 271 * Filter the cron request arguments.332 * Filters the cron request arguments. 272 333 * 273 334 * @since 3.5.0 335 * @since 4.5.0 The `$doing_wp_cron` parameter was added. 274 336 * 275 337 * @param array $cron_request_array { … … 286 348 * } 287 349 * } 350 * @param string $doing_wp_cron The unix timestamp of the cron lock. 288 351 */ 289 352 $cron_request = apply_filters( 'cron_request', array( … … 293 356 'timeout' => 0.01, 294 357 'blocking' => false, 295 /** This filter is documented in wp-includes/class- http.php */358 /** This filter is documented in wp-includes/class-wp-http-streams.php */ 296 359 'sslverify' => apply_filters( 'https_local_ssl_verify', false ) 297 360 ) 298 ) );361 ), $doing_wp_cron ); 299 362 300 363 wp_remote_post( $cron_request['url'], $cron_request['args'] ); … … 305 368 * 306 369 * @since 2.1.0 307 *308 * @return null When doesn't need to run Cron.309 370 */ 310 371 function wp_cron() { 311 312 372 // Prevent infinite loops caused by lack of wp-cron.php 313 373 if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) ) … … 335 395 336 396 /** 337 * Retrieve supported and filtered Cron recurrences.338 * 339 * The supported recurrences are 'hourly' and 'daily'. A plugin may add more by340 * hooking into the 'cron_schedules' filter. The filter accepts an array of341 * arrays. The outer array has a key that is the name of the schedule or for397 * Retrieve supported event recurrence schedules. 398 * 399 * The default supported recurrences are 'hourly', 'twicedaily', and 'daily'. A plugin may 400 * add more by hooking into the {@see 'cron_schedules'} filter. The filter accepts an array 401 * of arrays. The outer array has a key that is the name of the schedule or for 342 402 * example 'weekly'. The value is an array with two keys, one is 'interval' and 343 403 * the other is 'display'. … … 348 408 * 349 409 * The 'display' is the description. For the 'weekly' key, the 'display' would 350 * be <code>__('Once Weekly')</code>.410 * be `__( 'Once Weekly' )`. 351 411 * 352 412 * For your plugin, you will be passed an array. you can easily add your 353 413 * schedule by doing the following. 354 * <code>355 * // filter parameter variable name is 'array'356 * 357 * 358 * 'display' => __('Once Weekly')359 * 360 * </code>414 * 415 * // Filter parameter variable name is 'array'. 416 * $array['weekly'] = array( 417 * 'interval' => 604800, 418 * 'display' => __( 'Once Weekly' ) 419 * ); 420 * 361 421 * 362 422 * @since 2.1.0 … … 371 431 ); 372 432 /** 373 * Filter the non-default cron schedules.433 * Filters the non-default cron schedules. 374 434 * 375 435 * @since 2.1.0 … … 381 441 382 442 /** 383 * Retrieve Cron schedule for hook with arguments. 384 * 385 * @since 2.1.0 386 * 387 * @param string $hook Action hook to execute when cron is run. 388 * @param array $args Optional. Arguments to pass to the hook's callback function. 389 * @return string|bool False, if no schedule. Schedule on success. 443 * Retrieve the recurrence schedule for an event. 444 * 445 * @see wp_get_schedules() for available schedules. 446 * 447 * @since 2.1.0 448 * 449 * @param string $hook Action hook to identify the event. 450 * @param array $args Optional. Arguments passed to the event's callback function. 451 * @return string|false False, if no schedule. Schedule name on success. 390 452 */ 391 453 function wp_get_schedule($hook, $args = array()) { … … 411 473 * @access private 412 474 * 413 * @return array CRON info array.475 * @return false|array CRON info array. 414 476 */ 415 477 function _get_cron_array() { … … 432 494 * @access private 433 495 * 434 * @param array $cron Cron info array from {@link _get_cron_array()}.496 * @param array $cron Cron info array from _get_cron_array(). 435 497 */ 436 498 function _set_cron_array($cron) { … … 447 509 * @access private 448 510 * 449 * @param array $cron Cron info array from {@link _get_cron_array()}.511 * @param array $cron Cron info array from _get_cron_array(). 450 512 * @return array An upgraded Cron info array. 451 513 */
Note: See TracChangeset
for help on using the changeset viewer.