Jetpack_JSON_API_Cron_Endpoint

The WordPress Core Jetpack JSON API Cron 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_Endpoint extends Jetpack_JSON_API_Endpoint { 
  2. protected $needed_capabilities = 'manage_options'; 
  3.  
  4. protected function validate_call( $_blog_id, $capability, $check_manage_active = true ) { 
  5. parent::validate_call( $_blog_id, $capability, false ); 
  6.  
  7. protected function result() { 
  8. return array( 
  9. 'cron_array' => _get_cron_array(),  
  10. 'current_timestamp' => time() 
  11. ); 
  12.  
  13. protected function sanitize_hook( $hook ) { 
  14. return preg_replace( '/[^A-Za-z0-9-_]/', '', $hook ); 
  15.  
  16. protected function resolve_arguments() { 
  17. $args = $this->input(); 
  18. return isset( $args['arguments'] ) ? json_decode( $args['arguments'] ) : array(); 
  19.  
  20. protected function is_cron_locked( $gmt_time ) { 
  21. // The cron lock: a unix timestamp from when the cron was spawned. 
  22. $doing_cron_transient = $this->get_cron_lock(); 
  23. if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time ) ) { 
  24. return new WP_Error( 'cron-is-locked', 'Current there is a cron already happening.', 403 ); 
  25. return $doing_cron_transient; 
  26.  
  27. protected function maybe_unlock_cron( $doing_wp_cron ) { 
  28. if ( $this->get_cron_lock() == $doing_wp_cron ) { 
  29. delete_transient( 'doing_cron' ); 
  30.  
  31. protected function lock_cron() { 
  32. $lock = sprintf( '%.22F', microtime( true ) ); 
  33. set_transient( 'doing_cron', $lock ); 
  34. return $lock; 
  35.  
  36. protected function get_schedules( $hook, $args ) { 
  37. $crons = _get_cron_array(); 
  38. $key = md5(serialize($args)); 
  39. if ( empty( $crons ) ) 
  40. return array(); 
  41. $found = array(); 
  42. foreach ( $crons as $timestamp => $cron ) { 
  43. if ( isset( $cron[$hook][$key] ) ) 
  44. $found[] = $timestamp; 
  45.  
  46. return $found; 
  47.  
  48. /** 
  49. * This function is based on the one found in wp-cron.php with a similar name 
  50. * @return int 
  51. */ 
  52. protected function get_cron_lock() { 
  53. global $wpdb; 
  54.  
  55. $value = 0; 
  56. if ( wp_using_ext_object_cache() ) { 
  57. /** 
  58. * Skip local cache and force re-fetch of doing_cron transient 
  59. * in case another process updated the cache. 
  60. */ 
  61. $value = wp_cache_get( 'doing_cron', 'transient', true ); 
  62. } else { 
  63. $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", '_transient_doing_cron' ) ); 
  64. if ( is_object( $row ) ) { 
  65. $value = $row->option_value; 
  66. return $value;