Jetpack_JSON_API_Cron_Schedule_Endpoint

The WordPress Core Jetpack JSON API Cron Schedule 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_Schedule_Endpoint extends Jetpack_JSON_API_Cron_Endpoint { 
  2.  
  3. protected function result() { 
  4. $args = $this->input(); 
  5. if ( ! isset( $args['timestamp'] ) ) { 
  6. return new WP_Error( 'missing_argument', 'Please provide the timestamp argument', 400 ); 
  7.  
  8. if ( ! is_int( $args['timestamp'] ) || $args['timestamp'] < time() ) { 
  9. return new WP_Error( 'timestamp-invalid', 'Please provide timestamp that is an integer and set in the future', 400 ); 
  10.  
  11. if ( ! isset( $args['hook'] ) ) { 
  12. return new WP_Error( 'missing_argument', 'Please provide the hook argument', 400 ); 
  13.  
  14. $hook = $this->sanitize_hook( $args['hook'] ); 
  15.  
  16. $locked = $this->is_cron_locked( microtime( true ) ); 
  17. if ( is_wp_error( $locked ) ) { 
  18. return $locked; 
  19.  
  20. $arguments = $this->resolve_arguments(); 
  21. $next_scheduled = $this->get_schedules( $hook, $arguments ); 
  22.  
  23. if ( isset( $args['recurrence'] ) ) { 
  24. $schedules = wp_get_schedules(); 
  25. if ( ! isset( $schedules[ $args['recurrence'] ] ) ) { 
  26. return new WP_Error( 'invalid-recurrence', 'Please provide a valid recurrence argument', 400 ); 
  27.  
  28. if ( count( $next_scheduled ) > 0 ) { 
  29. return new WP_Error( 'event-already-scheduled', 'This event is ready scheduled', 400 ); 
  30. $lock = $this->lock_cron(); 
  31. wp_schedule_event( $args['timestamp'], $args['recurrence'], $hook, $arguments ); 
  32. $this->maybe_unlock_cron( $lock ); 
  33. return array( 'success' => true ); 
  34.  
  35. foreach( $next_scheduled as $scheduled_time ) { 
  36. if ( abs( $scheduled_time - $args['timestamp'] ) <= 10 * MINUTE_IN_SECONDS ) { 
  37. return new WP_Error( 'event-already-scheduled', 'This event is ready scheduled', 400 ); 
  38. $lock = $this->lock_cron(); 
  39. $next = wp_schedule_single_event( $args['timestamp'], $hook, $arguments ); 
  40. $this->maybe_unlock_cron( $lock ); 
  41. return array( 'success' => is_null( $next ) ? true : false );