| 2426 | | function wp_schedule_event($timestamp, $recurrence, $hook) { |
|---|
| 2427 | | $args = array_slice(func_get_args(), 3); |
|---|
| 2428 | | $crons = get_option('cron'); |
|---|
| 2429 | | $crons[$timestamp][$hook] = array('recur' => $recurrence, 'args' => $args); |
|---|
| 2430 | | ksort($crons); |
|---|
| 2431 | | update_option('cron', $crons); |
|---|
| 2432 | | } |
|---|
| 2433 | | |
|---|
| 2434 | | function wp_unschedule_event($timestamp, $hook) { |
|---|
| 2435 | | $crons = get_option('cron'); |
|---|
| 2436 | | unset($crons[$timestamp][$hook]); |
|---|
| 2437 | | if ( empty($crons[$timestamp]) ) |
|---|
| 2438 | | unset($crons[$timestamp]); |
|---|
| 2439 | | update_option('cron', $crons); |
|---|
| 2440 | | } |
|---|
| 2441 | | |
|---|
| 2442 | | function wp_clear_scheduled_hook($hook) { |
|---|
| 2443 | | while($timestamp = next_scheduled('scheduled_hook')) |
|---|
| 2444 | | wp_unschedule_event($timestamp, 'scheduled_hook'); |
|---|
| 2445 | | } |
|---|
| 2446 | | |
|---|
| 2447 | | function next_scheduled($hook) { |
|---|
| 2448 | | $crons = get_option('cron'); |
|---|
| 2449 | | if ( empty($crons) ) |
|---|
| 2450 | | return false; |
|---|
| 2451 | | foreach($crons as $timestamp => $cron) { |
|---|
| 2452 | | //if($timestamp <= time()) continue; |
|---|
| 2453 | | if(isset($cron[$hook])) return $timestamp; |
|---|
| 2454 | | } |
|---|
| 2455 | | return false; |
|---|
| 2456 | | } |
|---|
| 2457 | | |
|---|
| 2458 | | function spawn_cron() { |
|---|
| 2459 | | if (array_shift(array_keys(get_option('cron'))) > time()) return; |
|---|
| 2460 | | |
|---|
| 2461 | | $cron_url = get_settings('siteurl') . '/wp-cron.php'; |
|---|
| 2462 | | $parts = parse_url($cron_url); |
|---|
| 2463 | | $argyle = @ fsockopen($parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01); |
|---|
| 2464 | | if ( $argyle ) |
|---|
| 2465 | | fputs($argyle, "GET {$parts['path']}?time=" . time() . '&check=' |
|---|
| 2466 | | . md5(DB_PASS . '187425') . " HTTP/1.0\r\nHost: {$_SERVER['HTTP_HOST']}\r\n\r\n"); |
|---|
| 2467 | | } |
|---|
| 2468 | | |
|---|
| 2469 | | function wp_cron() { |
|---|
| 2470 | | $crons = get_option('cron'); |
|---|
| 2471 | | if (!is_array($crons) || array_shift(array_keys($crons)) > time()) |
|---|
| 2472 | | return; |
|---|
| 2473 | | |
|---|
| 2474 | | foreach ($crons as $timestamp => $cronhooks) { |
|---|
| 2475 | | if ($timestamp > current_time( 'timestamp' )) break; |
|---|
| 2476 | | foreach($cronhooks as $hook => $args) { |
|---|
| 2477 | | do_action($hook, $args['args']); |
|---|
| 2478 | | $recurrence = $args['recur']; |
|---|
| 2479 | | if ( 'hourly' == $recurrence ) { |
|---|
| 2480 | | $args = array_merge( array($timestamp + 3600, $recurrence, $hook), $args['args']); |
|---|
| 2481 | | call_user_func_array('wp_schedule_event', $args); |
|---|
| 2482 | | } else if ( 'daily' == $recurrence ) { |
|---|
| 2483 | | $args = array_merge( array($timestamp + 86400, $recurrence, $hook), $args['args']); |
|---|
| 2484 | | call_user_func_array('wp_schedule_event', $args); |
|---|
| 2485 | | } |
|---|
| 2486 | | |
|---|
| 2487 | | wp_unschedule_event($timestamp, $hook); |
|---|
| 2488 | | } |
|---|
| 2489 | | } |
|---|
| 2490 | | } |
|---|
| 2491 | | |
|---|