Jetpack_JSON_API_Cron_Post_Endpoint

The WordPress Core Jetpack JSON API Cron Post Endpoint class.

Defined (1)

The class is defined in the following location(s).

/json-endpoints/jetpack/class.jetpack-json-api-cron-endpoint.php  
  1. class Jetpack_JSON_API_Cron_Post_Endpoint extends Jetpack_JSON_API_Cron_Endpoint { 
  2.  
  3. protected function result() { 
  4. define( 'DOING_CRON', true ); 
  5. set_time_limit( 0 ); 
  6. $args = $this->input(); 
  7.  
  8. if ( false === $crons = _get_cron_array() ) { 
  9. return new WP_Error( 'no-cron-event', 'Currently there are no cron events', 400 ); 
  10.  
  11. $timestamps_to_run = array_keys( $crons ); 
  12. $gmt_time = microtime( true ); 
  13.  
  14. if ( isset( $timestamps_to_run[0] ) && $timestamps_to_run[0] > $gmt_time ) { 
  15. return new WP_Error( 'no-cron-event', 'Currently there are no cron events ready to be run', 400 ); 
  16.  
  17. $locked = $this->is_cron_locked( $gmt_time ); 
  18. if ( is_wp_error( $locked ) ) { 
  19. return $locked; 
  20.  
  21. $lock = $this->lock_cron(); 
  22. $processed_events = array(); 
  23.  
  24. foreach ( $crons as $timestamp => $cronhooks ) { 
  25. if ( $timestamp > $gmt_time && ! isset( $args[ 'hook' ] ) ) { 
  26. break; 
  27.  
  28. foreach ( $cronhooks as $hook => $hook_data ) { 
  29. if ( isset( $args[ 'hook' ] ) && ! in_array( $hook, $args['hook'] ) ) { 
  30. continue; 
  31.  
  32. foreach ( $hook_data as $hash => $hook_item ) { 
  33.  
  34. $schedule = $hook_item['schedule']; 
  35. $arguments = $hook_item['args']; 
  36.  
  37. if ( $schedule != false ) { 
  38. wp_reschedule_event( $timestamp, $schedule, $hook, $arguments ); 
  39.  
  40. wp_unschedule_event( $timestamp, $hook, $arguments ); 
  41.  
  42. do_action_ref_array( $hook, $arguments ); 
  43. $processed_events[] = array( $hook => $arguments ); 
  44.  
  45. // If the hook ran too long and another cron process stole the lock,  
  46. // or if we things are taking longer then 20 seconds then quit. 
  47. if ( ( $this->get_cron_lock() != $lock ) || ( $gmt_time + 20 > microtime( true ) ) ) { 
  48. $this->maybe_unlock_cron( $lock ); 
  49. return array( 'success' => $processed_events ); 
  50.  
  51.  
  52. $this->maybe_unlock_cron( $lock ); 
  53. return array( 'success' => $processed_events );