[ Index ]

WordPress Source Cross Reference

title

Body

[close]

/wp-includes/ -> cron.php (source)

   1  <?php
   2  
   3  function wp_schedule_single_event( $timestamp, $hook ) {
   4      $args = array_slice( func_get_args(), 2 );
   5      $crons = get_option( 'cron' );
   6      $crons[$timestamp][$hook] = array( 'schedule' => false, 'args' => $args );
   7      ksort( $crons );
   8      update_option( 'cron', $crons );
   9  }
  10  
  11  function wp_schedule_event( $timestamp, $recurrence, $hook ) {
  12      $args = array_slice( func_get_args(), 3 );
  13      $crons = get_option( 'cron' );
  14      $schedules = wp_get_schedules();
  15      if ( !isset( $schedules[$recurrence] ) )
  16          return false;
  17      $crons[$timestamp][$hook] = array( 'schedule' => $recurrence, 'args' => $args, 'interval' => $schedules[$recurrence]['interval'] );
  18      ksort( $crons );
  19      update_option( 'cron', $crons );
  20  }
  21  
  22  function wp_reschedule_event( $timestamp, $recurrence, $hook ) {
  23      $args = array_slice( func_get_args(), 3 );
  24      $crons = get_option( 'cron' );
  25      $schedules = wp_get_schedules();
  26      $interval = 0;
  27  
  28      // First we try to get it from the schedule
  29      if ( 0 == $interval )
  30          $interval = $schedules[$recurrence]['interval'];
  31      // Now we try to get it from the saved interval in case the schedule disappears
  32      if ( 0 == $interval )
  33          $interval = $crons[$timestamp][$hook]['interval'];
  34      // Now we assume something is wrong and fail to schedule
  35      if ( 0 == $interval )
  36          return false;
  37  
  38      while ( $timestamp < time() + 1 )
  39          $timestamp += $interval;
  40  
  41      wp_schedule_event( $timestamp, $recurrence, $hook );
  42  }
  43  
  44  function wp_unschedule_event( $timestamp, $hook ) {
  45      $crons = get_option( 'cron' );
  46      unset( $crons[$timestamp][$hook] );
  47      if ( empty($crons[$timestamp]) )
  48          unset( $crons[$timestamp] );
  49      update_option( 'cron', $crons );
  50  }
  51  
  52  function wp_clear_scheduled_hook( $hook ) {
  53      while ( $timestamp = wp_next_scheduled( $hook ) )
  54          wp_unschedule_event( $timestamp, $hook );
  55  }
  56  
  57  function wp_next_scheduled( $hook ) {
  58      $crons = get_option( 'cron' );
  59      if ( empty($crons) )
  60          return false;
  61      foreach ( $crons as $timestamp => $cron )
  62          if ( isset( $cron[$hook] ) )
  63              return $timestamp;
  64      return false;
  65  }
  66  
  67  function spawn_cron() {
  68      $crons = get_option( 'cron' );
  69      
  70      if ( !is_array($crons) )
  71          return;
  72      
  73      $keys = array_keys( $crons );
  74      if ( array_shift( $keys ) > time() )
  75          return;
  76  
  77      $cron_url = get_settings( 'siteurl' ) . '/wp-cron.php';
  78      $parts = parse_url( $cron_url );
  79  
  80      $argyle = @ fsockopen( $parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01 );
  81      if ( $argyle )
  82          fputs( $argyle,
  83                "GET {$parts['path']}?check=" . md5(DB_PASS . '187425') . " HTTP/1.0\r\n"
  84              . "Host: {$_SERVER['HTTP_HOST']}\r\n\r\n"
  85          );
  86  }
  87  
  88  function wp_cron() {
  89      $crons = get_option( 'cron' );
  90      
  91      if ( !is_array($crons) )
  92          return;
  93  
  94      $keys = array_keys( $crons );
  95      if ( array_shift( $keys ) > time() )
  96          return;
  97  
  98      $schedules = wp_get_schedules();
  99      foreach ( $crons as $timestamp => $cronhooks ) {
 100          if ( $timestamp > time() ) break;
 101          foreach ( $cronhooks as $hook => $args ) {
 102              if ( isset($schedules[$hook]['callback']) && !call_user_func( $schedules[$hook]['callback'] ) )
 103                  continue;
 104              spawn_cron();
 105              break 2;
 106          }
 107      }
 108  }
 109  
 110  function wp_get_schedules() {
 111      $schedules = array(
 112          'hourly' => array( 'interval' => 3600, 'display' => __('Once Hourly') ),
 113          'daily' => array( 'interval' => 86400, 'display' => __('Once Daily') ),
 114      );
 115      return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
 116  }
 117  
 118  ?>

Your comment here...

Name: Location:
Comments:


List: Classes | Functions | Variables | Constants | Tables

Generated: Sat Jul 15 11:57:04 2006 Courtesy of Taragana