Ticket #15148: 15148.2.diff
| File 15148.2.diff, 12.2 KB (added by ryan, 3 years ago) |
|---|
-
wp-includes/update.php
334 334 wp_update_themes(); 335 335 } 336 336 337 /** 338 * Schedule core, theme, and plugin update checks. 339 * 340 * @since 3.1.0 341 */ 342 function wp_schedule_update_checks() { 343 if ( !wp_next_scheduled('wp_version_check') && !defined('WP_INSTALLING') ) 344 wp_schedule_event(time(), 'twicedaily', 'wp_version_check'); 345 346 if ( !wp_next_scheduled('wp_update_plugins') && !defined('WP_INSTALLING') ) 347 wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins'); 348 349 if ( !wp_next_scheduled('wp_update_themes') && !defined('WP_INSTALLING') ) 350 wp_schedule_event(time(), 'twicedaily', 'wp_update_themes'); 351 } 352 337 353 if ( ! is_main_site() ) 338 354 return; 339 355 … … 352 368 add_action( 'admin_init', '_maybe_update_themes' ); 353 369 add_action( 'wp_update_themes', 'wp_update_themes' ); 354 370 355 if ( !wp_next_scheduled('wp_version_check') && !defined('WP_INSTALLING') ) 356 wp_schedule_event(time(), 'twicedaily', 'wp_version_check'); 371 add_action('init', 'wp_schedule_update_checks'); 357 372 358 if ( !wp_next_scheduled('wp_update_plugins') && !defined('WP_INSTALLING') )359 wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins');360 361 if ( !wp_next_scheduled('wp_update_themes') && !defined('WP_INSTALLING') )362 wp_schedule_event(time(), 'twicedaily', 'wp_update_themes');363 364 373 ?> -
wp-includes/cron.php
20 20 * @param array $args Optional. Arguments to pass to the hook's callback function. 21 21 */ 22 22 function wp_schedule_single_event( $timestamp, $hook, $args = array()) { 23 global $wp_cron_store; 24 23 25 // don't schedule a duplicate if there's already an identical event due in the next 10 minutes 24 26 $next = wp_next_scheduled($hook, $args); 25 27 if ( $next && $next <= $timestamp + 600 ) … … 33 35 if ( ! $event ) 34 36 return false; 35 37 36 $key = md5(serialize($event->args)); 37 38 $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args ); 39 uksort( $crons, "strnatcasecmp" ); 40 _set_cron_array( $crons ); 38 $wp_cron_store->insert_event($event); 41 39 } 42 40 43 41 /** … … 59 57 * @return bool|null False on failure, null when complete with scheduling event. 60 58 */ 61 59 function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array()) { 60 global $wp_cron_store; 61 62 62 $crons = _get_cron_array(); 63 63 $schedules = wp_get_schedules(); 64 64 … … 72 72 if ( ! $event ) 73 73 return false; 74 74 75 $key = md5(serialize($event->args)); 76 77 $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args, 'interval' => $event->interval ); 78 uksort( $crons, "strnatcasecmp" ); 79 _set_cron_array( $crons ); 75 $wp_cron_store->insert_event($event); 80 76 } 81 77 82 78 /** … … 91 87 * @return bool|null False on failure. Null when event is rescheduled. 92 88 */ 93 89 function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array()) { 94 $crons = _get_cron_array(); 95 $schedules = wp_get_schedules(); 96 $key = md5(serialize($args)); 90 global $wp_cron_store; 91 97 92 $interval = 0; 98 93 99 94 // First we try to get it from the schedule 100 if ( 0 == $interval)95 if ( isset($schedules[$recurrence]) ) 101 96 $interval = $schedules[$recurrence]['interval']; 102 97 // Now we try to get it from the saved interval in case the schedule disappears 103 if ( 0 == $interval ) 104 $interval = $crons[$timestamp][$hook][$key]['interval']; 98 if ( 0 == $interval ) { 99 $event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'args' => $args ); 100 $event = $wp_cron_store->get_event( $event ); 101 if ( $event ) 102 $interval = $event->interval; 103 } 105 104 // Now we assume something is wrong and fail to schedule 106 105 if ( 0 == $interval ) 107 106 return false; … … 132 131 * as those used when originally scheduling the event. 133 132 */ 134 133 function wp_unschedule_event( $timestamp, $hook, $args = array() ) { 135 $crons = _get_cron_array(); 136 $key = md5(serialize($args)); 137 unset( $crons[$timestamp][$hook][$key] ); 138 if ( empty($crons[$timestamp][$hook]) ) 139 unset( $crons[$timestamp][$hook] ); 140 if ( empty($crons[$timestamp]) ) 141 unset( $crons[$timestamp] ); 142 _set_cron_array( $crons ); 134 global $wp_cron_store; 135 136 $event = (object) array( 'hook' => $hook, 'timestamp' => $timestamp, 'args' => $args ); 137 $wp_cron_store->delete_event($event); 143 138 } 144 139 145 140 /** … … 172 167 * @return bool|int The UNIX timestamp of the next time the scheduled event will occur. 173 168 */ 174 169 function wp_next_scheduled( $hook, $args = array() ) { 175 $crons = _get_cron_array(); 176 $key = md5(serialize($args)); 177 if ( empty($crons) ) 170 global $wp_cron_store; 171 172 $event = (object) array( 'hook' => $hook, 'timestamp' => 'next', 'args' => $args ); 173 174 $event = $wp_cron_store->get_event( $event ); 175 176 if ( !$event ) 178 177 return false; 179 foreach ( $crons as $timestamp => $cron ) { 180 if ( isset( $cron[$hook][$key] ) ) 181 return $timestamp; 182 } 183 return false; 178 179 return $event->timestamp; 184 180 } 185 181 186 182 /** … … 191 187 * @return null Cron could not be spawned, because it is not needed to run. 192 188 */ 193 189 function spawn_cron( $local_time = 0 ) { 190 global $wp_cron_store; 194 191 195 192 if ( !$local_time ) 196 193 $local_time = time(); … … 220 217 return; 221 218 222 219 //sanity check 223 $crons = _get_cron_array();220 $crons = $wp_cron_store->_get_cron_array(); 224 221 if ( !is_array($crons) ) 225 222 return; 226 223 … … 260 257 * @return null When doesn't need to run Cron. 261 258 */ 262 259 function wp_cron() { 260 global $wp_cron_store; 263 261 264 262 // Prevent infinite loops caused by lack of wp-cron.php 265 263 if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) ) 266 264 return; 267 265 268 if ( false === $crons = _get_cron_array() )266 if ( false === $crons = $wp_cron_store->_get_cron_array() ) 269 267 return; 270 268 271 269 $local_time = time(); … … 334 332 * @return string|bool False, if no schedule. Schedule on success. 335 333 */ 336 334 function wp_get_schedule($hook, $args = array()) { 337 $crons = _get_cron_array(); 338 $key = md5(serialize($args)); 339 if ( empty($crons) ) 335 global $wp_cron_store; 336 337 $event = (object) array( 'hook' => $hook, 'timestamp' => 'next', 'args' => $args ); 338 339 $event = $wp_cron_store->get_event( $event ); 340 341 if ( !$event ) 340 342 return false; 341 foreach ( $crons as $timestamp => $cron ) { 342 if ( isset( $cron[$hook][$key] ) ) 343 return $cron[$hook][$key]['schedule']; 344 } 345 return false; 343 344 return $event->schedule; 346 345 } 347 346 348 347 // 349 348 // Private functions 350 349 // 351 350 352 /** 353 * Retrieve cron info array option. 354 * 355 * @since 2.1.0 356 * @access private 357 * 358 * @return array CRON info array. 359 */ 360 function _get_cron_array() { 361 $cron = get_option('cron'); 362 if ( ! is_array($cron) ) 363 return false; 351 class WP_Cron_Store { 352 function delete_event( $event ) { 353 $crons = $this->_get_cron_array(); 354 $key = md5(serialize($event->args)); 355 unset( $crons[$event->timestamp][$event->hook][$key] ); 356 if ( empty($crons[$event->timestamp][$event->hook]) ) 357 unset( $crons[$event->timestamp][$event->hook] ); 358 if ( empty($crons[$event->timestamp]) ) 359 unset( $crons[$event->timestamp] ); 360 $this->_set_cron_array( $crons ); 361 } 364 362 365 if ( !isset($cron['version']) ) 366 $cron = _upgrade_cron_array($cron); 363 function get_event( $event ) { 364 $crons = $this->_get_cron_array(); 365 $key = md5(serialize($event->args)); 366 if ( empty($crons) ) 367 return false; 368 369 if ( empty($event->timestamp) || 'next' == $event->timestamp ) { 370 foreach ( $crons as $timestamp => $cron ) { 371 if ( isset( $cron[$event->hook][$key] ) ) 372 return (object) array( 'hook' => $event->hook, 'args' => $event->args, 'timestamp' => $timestamp, 'schedule' => $cron[$event->hook][$key]['schedule'], 'interval' => $cron[$event->hook][$key]['interval']); 373 } 374 return false; 375 } 367 376 368 unset($cron['version']); 377 if ( isset($cron[$event->timestamp][$event->hook][$key]) ) 378 return (object) array( 'hook' => $event->hook, 'args' => $event->args, 'timestamp' => $event->timestamp, 'schedule' => $cron[$event->timestamp][$event->hook][$key]['schedule'], 'interval' => $cron[$event->timestamp][$event->hook][$key]['interval']); 369 379 370 return $cron; 371 } 372 373 /** 374 * Updates the CRON option with the new CRON array. 375 * 376 * @since 2.1.0 377 * @access private 378 * 379 * @param array $cron Cron info array from {@link _get_cron_array()}. 380 */ 381 function _set_cron_array($cron) { 382 $cron['version'] = 2; 383 update_option( 'cron', $cron ); 384 } 385 386 /** 387 * Upgrade a Cron info array. 388 * 389 * This function upgrades the Cron info array to version 2. 390 * 391 * @since 2.1.0 392 * @access private 393 * 394 * @param array $cron Cron info array from {@link _get_cron_array()}. 395 * @return array An upgraded Cron info array. 396 */ 397 function _upgrade_cron_array($cron) { 398 if ( isset($cron['version']) && 2 == $cron['version']) 380 return false; 381 } 382 383 function get_events( $args ) { 384 // @todo 385 return null; 386 } 387 388 function insert_event( $event ) { 389 $key = md5(serialize($event->args)); 390 391 $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args, 'interval' => $event->interval ); 392 uksort( $crons, "strnatcasecmp" ); 393 $this->_set_cron_array( $crons ); 394 } 395 396 /** 397 * Retrieve cron info array option. 398 * 399 * @since 2.1.0 400 * @access private 401 * 402 * @return array CRON info array. 403 */ 404 function _get_cron_array() { 405 $cron = get_option('cron'); 406 if ( ! is_array($cron) ) 407 return false; 408 409 if ( !isset($cron['version']) ) 410 $cron = $this->_upgrade_cron_array($cron); 411 412 unset($cron['version']); 413 399 414 return $cron; 400 401 $new_cron = array(); 402 403 foreach ( (array) $cron as $timestamp => $hooks) { 404 foreach ( (array) $hooks as $hook => $args ) { 405 $key = md5(serialize($args['args'])); 406 $new_cron[$timestamp][$hook][$key] = $args; 415 } 416 417 /** 418 * Updates the CRON option with the new CRON array. 419 * 420 * @since 2.1.0 421 * @access private 422 * 423 * @param array $cron Cron info array from {@link _get_cron_array()}. 424 */ 425 function _set_cron_array($cron) { 426 $cron['version'] = 2; 427 update_option( 'cron', $cron ); 428 } 429 430 /** 431 * Upgrade a Cron info array. 432 * 433 * This function upgrades the Cron info array to version 2. 434 * 435 * @since 2.1.0 436 * @access private 437 * 438 * @param array $cron Cron info array from {@link _get_cron_array()}. 439 * @return array An upgraded Cron info array. 440 */ 441 function _upgrade_cron_array($cron) { 442 if ( isset($cron['version']) && 2 == $cron['version']) 443 return $cron; 444 445 $new_cron = array(); 446 447 foreach ( (array) $cron as $timestamp => $hooks) { 448 foreach ( (array) $hooks as $hook => $args ) { 449 $key = md5(serialize($args['args'])); 450 $new_cron[$timestamp][$hook][$key] = $args; 451 } 407 452 } 453 454 $new_cron['version'] = 2; 455 update_option( 'cron', $new_cron ); 456 return $new_cron; 408 457 } 409 410 $new_cron['version'] = 2;411 update_option( 'cron', $new_cron );412 return $new_cron;413 458 } 414 459 415 460 // stub for checking server timer accuracy, using outside standard time sources -
wp-settings.php
99 99 // Run the installer if WordPress is not installed. 100 100 wp_not_installed(); 101 101 102 // Load cron 103 require_once( ABSPATH . WPINC . '/cron.php' ); 104 if ( file_exists( WP_CONTENT_DIR . '/cron.php' ) ) 105 require_once( WP_CONTENT_DIR . '/cron.php' ); 106 107 if ( !isset( $wp_cron_store ) ) 108 $wp_cron_store = new WP_Cron_Store; 109 102 110 // Load most of WordPress. 103 111 require( ABSPATH . WPINC . '/formatting.php' ); 104 112 require( ABSPATH . WPINC . '/capabilities.php' ); … … 120 128 require( ABSPATH . WPINC . '/bookmark.php' ); 121 129 require( ABSPATH . WPINC . '/bookmark-template.php' ); 122 130 require( ABSPATH . WPINC . '/kses.php' ); 123 require( ABSPATH . WPINC . '/cron.php' );124 131 require( ABSPATH . WPINC . '/deprecated.php' ); 125 132 require( ABSPATH . WPINC . '/script-loader.php' ); 126 133 require( ABSPATH . WPINC . '/taxonomy.php' ); -
wp-cron.php
26 26 require_once('./wp-load.php'); 27 27 } 28 28 29 if ( false === $crons = _get_cron_array() )29 if ( false === $crons = $wp_cron_store->_get_cron_array() ) 30 30 die(); 31 31 32 32 $keys = array_keys( $crons );