Нет описания

Cron.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*******************************************************************************
  3. * Copyright (c) 2019, Code Atlantic LLC
  4. ******************************************************************************/
  5. if ( ! defined( 'ABSPATH' ) ) {
  6. exit;
  7. }
  8. /**
  9. * Class PUM_Utils_Cron
  10. *
  11. * @since 1.8.0
  12. */
  13. class PUM_Utils_Cron {
  14. /**
  15. * PUM_Utils_Cron constructor.
  16. */
  17. public function __construct() {
  18. add_filter( 'cron_schedules', array( $this, 'add_schedules' ) );
  19. add_action( 'wp', array( $this, 'schedule_events' ) );
  20. }
  21. /**
  22. * Registers new cron schedules
  23. *
  24. * @param array $schedules
  25. *
  26. * @return array
  27. */
  28. public function add_schedules( $schedules = array() ) {
  29. // Adds once weekly to the existing schedules.
  30. $schedules['weekly'] = array(
  31. 'interval' => 604800,
  32. 'display' => __( 'Once Weekly', 'popup-maker' )
  33. );
  34. return $schedules;
  35. }
  36. /**
  37. * Schedules our events
  38. */
  39. public function schedule_events() {
  40. $this->weekly_events();
  41. $this->daily_events();
  42. }
  43. /**
  44. * Schedule weekly events
  45. */
  46. private function weekly_events() {
  47. if ( ! wp_next_scheduled( 'pum_weekly_scheduled_events' ) ) {
  48. wp_schedule_event( current_time( 'timestamp' ), 'weekly', 'pum_weekly_scheduled_events' );
  49. }
  50. }
  51. /**
  52. * Schedule daily events
  53. */
  54. private function daily_events() {
  55. if ( ! wp_next_scheduled( 'pum_daily_scheduled_events' ) ) {
  56. wp_schedule_event( current_time( 'timestamp' ), 'daily', 'pum_daily_scheduled_events' );
  57. }
  58. }
  59. }