Ticket #2425: cron2.diff
File cron2.diff, 7.5 KB (added by , 19 years ago) |
---|
-
wp-includes/functions.php
2420 2420 return $wpdb->num_queries; 2421 2421 } 2422 2422 2423 function wp_schedule_event($timestamp, $recurrence, $hook) {2424 $args = array_slice(func_get_args(), 3);2425 $crons = get_option('cron');2426 $crons[$timestamp][$hook] = array('recur' => $recurrence, 'args' => $args);2427 ksort($crons);2428 update_option('cron', $crons);2429 }2430 2431 function wp_unschedule_event($timestamp, $hook) {2432 $crons = get_option('cron');2433 unset($crons[$timestamp][$hook]);2434 if ( empty($crons[$timestamp]) )2435 unset($crons[$timestamp]);2436 update_option('cron', $crons);2437 }2438 2439 function wp_clear_scheduled_hook($hook) {2440 while($timestamp = next_scheduled('scheduled_hook'))2441 wp_unschedule_event($timestamp, 'scheduled_hook');2442 }2443 2444 function next_scheduled($hook) {2445 $crons = get_option('cron');2446 if ( empty($crons) )2447 return false;2448 foreach($crons as $timestamp => $cron) {2449 //if($timestamp <= time()) continue;2450 if(isset($cron[$hook])) return $timestamp;2451 }2452 return false;2453 }2454 2455 function spawn_cron() {2456 if (array_shift(array_keys(get_option('cron'))) > time()) return;2457 2458 $cron_url = get_settings('siteurl') . '/wp-cron.php';2459 $parts = parse_url($cron_url);2460 $argyle = @ fsockopen($parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01);2461 if ( $argyle )2462 fputs($argyle, "GET {$parts['path']}?time=" . time() . '&check='2463 . md5(DB_PASS . '187425') . " HTTP/1.0\r\nHost: {$_SERVER['HTTP_HOST']}\r\n\r\n");2464 }2465 2466 function wp_cron() {2467 $crons = get_option('cron');2468 if (!is_array($crons) || array_shift(array_keys($crons)) > time())2469 return;2470 2471 foreach ($crons as $timestamp => $cronhooks) {2472 if ($timestamp > current_time( 'timestamp' )) break;2473 foreach($cronhooks as $hook => $args) {2474 do_action($hook, $args['args']);2475 $recurrence = $args['recur'];2476 if ( 'hourly' == $recurrence ) {2477 $args = array_merge( array($timestamp + 3600, $recurrence, $hook), $args['args']);2478 call_user_func_array('wp_schedule_event', $args);2479 } else if ( 'daily' == $recurrence ) {2480 $args = array_merge( array($timestamp + 86400, $recurrence, $hook), $args['args']);2481 call_user_func_array('wp_schedule_event', $args);2482 }2483 2484 wp_unschedule_event($timestamp, $hook);2485 }2486 }2487 }2488 2489 2423 function privacy_ping_filter( $sites ) { 2490 2424 if ( get_option('blog_public') ) 2491 2425 return $sites; -
wp-includes/cron.php
1 <?php 2 function wp_schedule_single_event($timestamp, $hook) { 3 $args = array_slice(func_get_args(), 2); 4 $crons = get_option('cron'); 5 $crons[$timestamp][$hook] = array('schedule' => false, 'args' => $args); 6 ksort($crons); 7 update_option('cron', $crons); 8 } 9 function wp_schedule_new_event($timestamp, $recurrence, $hook) { 10 $args = array_slice(func_get_args(), 3); 11 $crons = get_option('cron'); 12 $schedules = wp_get_schedules(); 13 if(!isset($schedules[$recurrence])) 14 return false; 15 $crons[$timestamp][$hook] = array('schedule' => $recurrence, 'args' => $args, 'interval' => $schedules[$recurrence]['interval']); 16 ksort($crons); 17 update_option('cron', $crons); 18 } 19 20 21 function wp_reschedule_event($timestamp, $recurrence, $hook) { 22 $args = array_slice(func_get_args(), 3); 23 $crons = get_option('cron'); 24 $schedules = wp_get_schedules(); 25 $interval = 0; 26 27 // First we try to get it from the schedule 28 if( 0 == $interval ) 29 $interval = $schedules[$recurrence]['interval']; 30 // Now we try to get it from the saved interval in case the schedule disappears 31 if( 0 == $interval ) 32 $interval = $crons[$timestamp][$hook]['interval']; 33 // Now we assume something is wrong and fail to schedule 34 if( 0 == $interval ) 35 return false; 36 37 while($timestamp < time() + 1) { 38 $timestamp += $interval; 39 } 40 wp_schedule_new_event($timestamp, $recurrence, $hook); 41 } 42 43 function wp_unschedule_event($timestamp, $hook) { 44 $crons = get_option('cron'); 45 unset($crons[$timestamp][$hook]); 46 if ( empty($crons[$timestamp]) ) 47 unset($crons[$timestamp]); 48 update_option('cron', $crons); 49 } 50 51 function wp_clear_scheduled_hook($hook) { 52 while($timestamp = next_scheduled($hook)) 53 wp_unschedule_event($timestamp, $hook); 54 } 55 56 function wp_next_scheduled($hook) { 57 $crons = get_option('cron'); 58 if ( empty($crons) ) 59 return false; 60 foreach($crons as $timestamp => $cron) { 61 //if($timestamp <= time()) continue; 62 if(isset($cron[$hook])) return $timestamp; 63 } 64 return false; 65 } 66 67 function spawn_cron() { 68 if (array_shift(array_keys(get_option('cron'))) > time()) return; 69 70 //Since execute pings had CGI problems, but I'd like to test this without this code first 71 // It seems to be working on CGI here, please report if you have issues 72 /* if ( substr(php_sapi_name(), 0, 3) == 'cgi' ) { 73 echo '<iframe src="' . $cron_url . '"></iframe>'; 74 }*/ 75 76 $cron_url = get_settings('siteurl') . '/wp-cron.php'; 77 $parts = parse_url($cron_url); 78 79 $argyle = @ fsockopen($parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01); 80 if ( $argyle ) 81 fputs($argyle, "GET {$parts['path']}?time=" . time() . '&check=' 82 . md5(DB_PASS . '187425') . " HTTP/1.0\r\nHost: {$_SERVER['HTTP_HOST']}\r\n\r\n"); 83 } 84 85 function wp_cron() { 86 $crons = get_option('cron'); 87 if (!is_array($crons) || array_shift(array_keys($crons)) > time()) 88 return; 89 90 $schedules = wp_get_schedules(); 91 foreach ($crons as $timestamp => $cronhooks) { 92 if ($timestamp > time()) break; 93 foreach($cronhooks as $hook => $args) { 94 if(isset($schedules[$hook]['callback']) && !call_user_func($schedules[$hook]['callback'])) 95 continue; 96 spawn_cron(); 97 break 2; 98 } 99 } 100 } 101 102 function wp_get_schedules() { 103 $schedules = array( 104 'hourly' => array('interval' => 3600, 'display' => __('Once Hourly')), 105 'daily' => array('interval' => 86400, 'display' => __('Once Daily')), 106 ); 107 return array_merge(apply_filters('cron_schedules', array()), $schedules); 108 } 109 ?> 110 No newline at end of file -
wp-cron.php
1 <?php 2 ignore_user_abort(true); 3 define('DOING_CRON', TRUE); 4 require_once('wp-config.php'); 5 6 $crons = get_option('cron'); 7 if (!is_array($crons) || array_shift(array_keys($crons)) > time()) 8 return; 9 foreach ($crons as $timestamp => $cronhooks) { 10 if ($timestamp > time()) break; 11 foreach($cronhooks as $hook => $args) { 12 do_action($hook, $args['args']); 13 $schedule = $args['schedule']; 14 if($schedule != false) { 15 fwrite($fp, var_export($schedules[$schedule])); 16 $args = array_merge( array($timestamp, $schedule, $hook), $args['args']); 17 call_user_func_array('wp_reschedule_event', $args); 18 } 19 wp_unschedule_event($timestamp, $hook); 20 } 21 } 22 ?> -
wp-includes/functions-post.php
210 210 add_post_meta($post_ID, '_wp_page_template', $page_template, true); 211 211 } 212 212 213 if ( 'future' == $post_status ) 214 wp_schedule_event(mysql2date('U', $post_date), 'once', 'publish_future_post', $post_ID); 215 213 if ( 'future' == $post_status ) { 214 wp_schedule_single_event(mysql2date('U', $post_date), 'publish_future_post', $post_ID); 215 } 216 216 217 do_action('save_post', $post_ID); 217 218 do_action('wp_insert_post', $post_ID); 218 219