Changeset 43050 for trunk/src/wp-includes/cron.php
- Timestamp:
- 05/01/2018 02:04:25 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/cron.php
r42343 r43050 22 22 * 23 23 * @since 2.1.0 24 * @since 5.0.0 Return value modified to boolean indicating success or failure. 25 * 24 26 * @link https://codex.wordpress.org/Function_Reference/wp_schedule_single_event 25 27 * … … 27 29 * @param string $hook Action hook to execute when the event is run. 28 30 * @param array $args Optional. Array containing each separate argument to pass to the hook's callback function. 29 * @return false|void False if the event did not get scheduled.31 * @return bool True if event successfully scheduled. False for failure. 30 32 */ 31 33 function wp_schedule_single_event( $timestamp, $hook, $args = array() ) { … … 78 80 ); 79 81 uksort( $crons, 'strnatcasecmp' ); 80 _set_cron_array( $crons );82 return _set_cron_array( $crons ); 81 83 } 82 84 … … 100 102 * 101 103 * @since 2.1.0 104 * @since 5.0.0 Return value modified to boolean indicating success or failure. 105 * 102 106 * @link https://codex.wordpress.org/Function_Reference/wp_schedule_event 103 107 * … … 106 110 * @param string $hook Action hook to execute when the event is run. 107 111 * @param array $args Optional. Array containing each separate argument to pass to the hook's callback function. 108 * @return false|void False if the event did not get scheduled.112 * @return bool True if event successfully scheduled. False for failure. 109 113 */ 110 114 function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array() ) { … … 144 148 ); 145 149 uksort( $crons, 'strnatcasecmp' ); 146 _set_cron_array( $crons );150 return _set_cron_array( $crons ); 147 151 } 148 152 … … 151 155 * 152 156 * @since 2.1.0 157 * @since 5.0.0 Return value modified to boolean indicating success or failure. 153 158 * 154 159 * @param int $timestamp Unix timestamp (UTC) for when to next run the event. … … 156 161 * @param string $hook Action hook to execute when the event is run. 157 162 * @param array $args Optional. Array containing each separate argument to pass to the hook's callback function. 158 * @return false|void False if the event did not get rescheduled.163 * @return bool True if event successfully rescheduled. False for failure. 159 164 */ 160 165 function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() ) { … … 190 195 } 191 196 192 wp_schedule_event( $timestamp, $recurrence, $hook, $args );197 return wp_schedule_event( $timestamp, $recurrence, $hook, $args ); 193 198 } 194 199 … … 200 205 * 201 206 * @since 2.1.0 207 * @since 5.0.0 Return value modified to boolean indicating success or failure. 202 208 * 203 209 * @param int $timestamp Unix timestamp (UTC) of the event. … … 206 212 * Although not passed to a callback, these arguments are used to uniquely identify the 207 213 * event, so they should be the same as those used when originally scheduling the event. 208 * @return false|void False if the event did not get unscheduled.214 * @return bool True if event successfully unscheduled. False for failure. 209 215 */ 210 216 function wp_unschedule_event( $timestamp, $hook, $args = array() ) { … … 223 229 unset( $crons[ $timestamp ] ); 224 230 } 225 _set_cron_array( $crons );231 return _set_cron_array( $crons ); 226 232 } 227 233 … … 229 235 * Unschedules all events attached to the hook with the specified arguments. 230 236 * 231 * @since 2.1.0 237 * Warning: This function may return Boolean FALSE, but may also return a non-Boolean 238 * value which evaluates to FALSE. For information about casting to booleans see the 239 * {@link https://php.net/manual/en/language.types.boolean.php PHP documentation}. Use 240 * the `===` operator for testing the return value of this function. 241 * 242 * @since 2.1.0 243 * @since 5.0.0 Return value modified to indicate success or failure. 232 244 * 233 245 * @param string $hook Action hook, the execution of which will be unscheduled. 234 246 * @param array $args Optional. Arguments that were to be passed to the hook's callback function. 247 * @return bool|int On success an integer indicating number of events unscheduled (0 indicates no 248 * events were registered with the hook and arguments combination), false if 249 * unscheduling one or more events fail. 235 250 */ 236 251 function wp_clear_scheduled_hook( $hook, $args = array() ) { … … 247 262 $crons = _get_cron_array(); 248 263 if ( empty( $crons ) ) { 249 return; 250 } 251 252 $key = md5( serialize( $args ) ); 264 return 0; 265 } 266 267 $results = array(); 268 $key = md5( serialize( $args ) ); 253 269 foreach ( $crons as $timestamp => $cron ) { 254 270 if ( isset( $cron[ $hook ][ $key ] ) ) { 255 wp_unschedule_event( $timestamp, $hook, $args ); 256 } 257 } 271 $results[] = wp_unschedule_event( $timestamp, $hook, $args ); 272 } 273 } 274 if ( in_array( false, $results, true ) ) { 275 return false; 276 } 277 return count( $results ); 258 278 } 259 279 … … 263 283 * Can be useful for plugins when deactivating to clean up the cron queue. 264 284 * 285 * Warning: This function may return Boolean FALSE, but may also return a non-Boolean 286 * value which evaluates to FALSE. For information about casting to booleans see the 287 * {@link https://php.net/manual/en/language.types.boolean.php PHP documentation}. Use 288 * the `===` operator for testing the return value of this function. 289 * 265 290 * @since 4.9.0 291 * @since 5.0.0 Return value added to indicate success or failure. 266 292 * 267 293 * @param string $hook Action hook, the execution of which will be unscheduled. 294 * @return bool|int On success an integer indicating number of events unscheduled (0 indicates no 295 * events were registered on the hook), false if unscheduling fails. 268 296 */ 269 297 function wp_unschedule_hook( $hook ) { 270 298 $crons = _get_cron_array(); 271 299 if ( empty( $crons ) ) { 300 return 0; 301 } 302 303 $results = array(); 272 304 foreach ( $crons as $timestamp => $args ) { 305 if ( ! empty( $crons[ $timestamp ][ $hook ] ) ) { 306 $results[] = count( $crons[ $timestamp ][ $hook ] ); 307 } 273 308 unset( $crons[ $timestamp ][ $hook ] ); 274 309 … … 278 313 } 279 314 280 _set_cron_array( $crons ); 315 /* 316 * If the results are empty (zero events to unschedule), no attempt 317 * to update the cron array is required. 318 */ 319 if ( empty( $results ) ) { 320 return 0; 321 } 322 if ( _set_cron_array( $crons ) ) { 323 return array_sum( $results ); 324 } 325 return false; 281 326 } 282 327 … … 310 355 * 311 356 * @since 2.1.0 357 * @since 5.0.0 Return values added. 312 358 * 313 359 * @param int $gmt_time Optional. Unix timestamp (UTC). Default 0 (current time is used). 360 * @return bool True if spawned, false if no events spawned. 314 361 */ 315 362 function spawn_cron( $gmt_time = 0 ) { … … 319 366 320 367 if ( defined( 'DOING_CRON' ) || isset( $_GET['doing_wp_cron'] ) ) { 321 return ;368 return false; 322 369 } 323 370 … … 337 384 // don't run if another process is currently running it or more than once every 60 sec. 338 385 if ( $lock + WP_CRON_LOCK_TIMEOUT > $gmt_time ) { 339 return ;386 return false; 340 387 } 341 388 … … 343 390 $crons = _get_cron_array(); 344 391 if ( ! is_array( $crons ) ) { 345 return ;392 return false; 346 393 } 347 394 348 395 $keys = array_keys( $crons ); 349 396 if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) { 350 return ;397 return false; 351 398 } 352 399 353 400 if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) { 354 401 if ( 'GET' !== $_SERVER['REQUEST_METHOD'] || defined( 'DOING_AJAX' ) || defined( 'XMLRPC_REQUEST' ) ) { 355 return ;402 return false; 356 403 } 357 404 … … 369 416 370 417 WP_DEBUG ? include_once( ABSPATH . 'wp-cron.php' ) : @include_once( ABSPATH . 'wp-cron.php' ); 371 return ;418 return true; 372 419 } 373 420 … … 410 457 ); 411 458 412 wp_remote_post( $cron_request['url'], $cron_request['args'] ); 459 $result = wp_remote_post( $cron_request['url'], $cron_request['args'] ); 460 return ! is_wp_error( $result ); 413 461 } 414 462 … … 416 464 * Run scheduled callbacks or spawn cron for all scheduled events. 417 465 * 418 * @since 2.1.0 466 * Warning: This function may return Boolean FALSE, but may also return a non-Boolean 467 * value which evaluates to FALSE. For information about casting to booleans see the 468 * {@link https://php.net/manual/en/language.types.boolean.php PHP documentation}. Use 469 * the `===` operator for testing the return value of this function. 470 * 471 * @since 2.1.0 472 * @since 5.0.0 Return value added to indicate success or failure. 473 * 474 * @return bool|int On success an integer indicating number of events spawned (0 indicates no 475 * events needed to be spawned), false if spawning fails for one or more events. 419 476 */ 420 477 function wp_cron() { 421 478 // Prevent infinite loops caused by lack of wp-cron.php 422 479 if ( strpos( $_SERVER['REQUEST_URI'], '/wp-cron.php' ) !== false || ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ) { 423 return; 424 } 425 426 if ( false === $crons = _get_cron_array() ) { 427 return; 480 return 0; 481 } 482 483 $crons = _get_cron_array(); 484 if ( false === $crons ) { 485 return 0; 428 486 } 429 487 … … 431 489 $keys = array_keys( $crons ); 432 490 if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) { 433 return ;491 return 0; 434 492 } 435 493 436 494 $schedules = wp_get_schedules(); 495 $results = array(); 437 496 foreach ( $crons as $timestamp => $cronhooks ) { 438 497 if ( $timestamp > $gmt_time ) { … … 443 502 continue; 444 503 } 445 spawn_cron( $gmt_time );504 $results[] = spawn_cron( $gmt_time ); 446 505 break 2; 447 506 } 448 507 } 508 509 if ( in_array( false, $results, true ) ) { 510 return false; 511 } 512 return count( $results ); 449 513 } 450 514 … … 559 623 * 560 624 * @since 2.1.0 625 * @since 5.0.0 Return value modified to outcome of {@see update_option}. 626 * 561 627 * @access private 562 628 * 563 629 * @param array $cron Cron info array from _get_cron_array(). 630 * @return bool True if cron array updated, false on failure. 564 631 */ 565 632 function _set_cron_array( $cron ) { 566 633 $cron['version'] = 2; 567 update_option( 'cron', $cron );634 return update_option( 'cron', $cron ); 568 635 } 569 636
Note: See TracChangeset
for help on using the changeset viewer.