Jetpack_JSON_API_Cron_Unschedule_Endpoint

The WordPress Core Jetpack JSON API Cron Unschedule 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_Unschedule_Endpoint extends Jetpack_JSON_API_Cron_Endpoint { 
  2.  
  3. protected function result() { 
  4. $args = $this->input(); 
  5.  
  6. if ( !isset( $args['hook'] ) ) { 
  7. return new WP_Error( 'missing_argument', 'Please provide the hook argument', 400 ); 
  8.  
  9. $hook = $this->sanitize_hook( $args['hook'] ); 
  10.  
  11. $locked = $this->is_cron_locked( microtime( true ) ); 
  12. if ( is_wp_error( $locked ) ) { 
  13. return $locked; 
  14.  
  15. $crons = _get_cron_array(); 
  16. if ( empty( $crons ) ) { 
  17. return new WP_Error( 'cron-not-present', 'Unable to unschedule an event, no events in the cron', 400 ); 
  18.  
  19. $arguments = $this->resolve_arguments(); 
  20.  
  21. if ( isset( $args['timestamp'] ) ) { 
  22. $next_schedulded = $this->get_schedules( $hook, $arguments ); 
  23. if ( in_array( $args['timestamp'], $next_schedulded ) ) { 
  24. return new WP_Error( 'event-not-present', 'Unable to unschedule the event, the event doesn\'t exist', 400 ); 
  25.  
  26. $lock = $this->lock_cron(); 
  27. wp_unschedule_event( $args['timestamp'], $hook, $arguments ); 
  28. $this->maybe_unlock_cron( $lock ); 
  29. return array( 'success' => true ); 
  30. $lock = $this->lock_cron(); 
  31. wp_clear_scheduled_hook( $hook, $arguments ); 
  32. $this->maybe_unlock_cron( $lock ); 
  33. return array( 'success' => true );