class-wp-cron.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. // https://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
  3. add_filter('cron_schedules', array('Booked_WC_WP_Crons', 'cron_schedules'));
  4. class Booked_WC_WP_Crons {
  5. private function __construct() {
  6. if ( Booked_WC_Settings::get_option('enable_auto_cleanup') === 'enable' ) {
  7. $this->activate_scheduler();
  8. }
  9. }
  10. public static function setup(){
  11. return new self();
  12. }
  13. public static function cron_schedules( $schedules ) {
  14. $schedules['weekly'] = array(
  15. 'interval' => 60 * 60 * 24 * 7,
  16. 'display' => __('Weekly', 'booked-woocommerce-payments')
  17. );
  18. $schedules['twiceweekly'] = array(
  19. 'interval' => 60 * 60 * 24 * 3.5,
  20. 'display' => __('Twice Weekly', 'booked-woocommerce-payments')
  21. );
  22. $schedules['monthly'] = array(
  23. 'interval' => 60 * 60 * 24 * 30.5,
  24. 'display' => __('Monthly', 'booked-woocommerce-payments')
  25. );
  26. $schedules['twicemonthly'] = array(
  27. 'interval' => 60 * 60 * 24 * 15,
  28. 'display' => __('Twice Monthly', 'booked-woocommerce-payments')
  29. );
  30. $schedules['twicehourly'] = array(
  31. 'interval' => 60 * 30,
  32. 'display' => __('Every 30 Minutes', 'booked-woocommerce-payments')
  33. );
  34. $schedules['everyfifteen'] = array(
  35. 'interval' => 60 * 15,
  36. 'display' => __('Every 15 Minutes', 'booked-woocommerce-payments')
  37. );
  38. $schedules['everyfive'] = array(
  39. 'interval' => 60 * 5,
  40. 'display' => __('Every 5 Minutes', 'booked-woocommerce-payments')
  41. );
  42. return $schedules;
  43. }
  44. protected function activate_scheduler() {
  45. $mode = Booked_WC_Settings::get_option('cleanup_mode');
  46. $recurrence = $mode;
  47. $schedule_name = BOOKED_WC_PLUGIN_PREFIX . 'cron_' . $recurrence;
  48. if ($recurrence && !wp_next_scheduled( $schedule_name) ) {
  49. wp_schedule_event(time(), $recurrence, $schedule_name);
  50. }
  51. add_action($schedule_name, array($this, 'execute_cron'), 20 );
  52. }
  53. public function execute_cron() {
  54. Booked_WC_Cleanup::start();
  55. }
  56. }