PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 1.0.2
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v1.0.2
2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 All 96 releases
sureforms / inc / events-scheduler.php
events-scheduler.php
60 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * SureForms events scheduler class.
4 *
5 * @package sureforms.
6 * @since 0.0.2
7 */
8
9 namespace SRFM\Inc;
10
11 use SRFM\Inc\Traits\Get_Instance;
12
13 /**
14 * SureForms events scheduler class.
15 *
16 * @since 0.0.2
17 */
18 class Events_Scheduler {
19 use Get_Instance;
20
21 /**
22 * Constructor
23 *
24 * @since 0.0.2
25 */
26 public function __construct() {
27 add_action( 'init', [ $this, 'srfm_schedule_daily_action' ] );
28 }
29
30 /**
31 * Schedules a action that runs every 24 hours for SureForms.
32 *
33 * @hooked - init
34 * @uses as_has_scheduled_action() To check if the action is already scheduled.
35 * @uses as_schedule_recurring_action() To schedule a recurring action.
36 * @link https://actionscheduler.org/api/
37 * @since 0.0.2
38 * @return void
39 */
40 public function srfm_schedule_daily_action() {
41 // Check if the action is not scheduled. Then schedule a new action.
42 if ( false === as_has_scheduled_action( 'srfm_daily_scheduled_action' ) ) {
43 // Shedule a recurring action srfm_daily_scheduled_events that runs every 24 hours.
44 as_schedule_recurring_action( strtotime( 'tomorrow' ), DAY_IN_SECONDS, 'srfm_daily_scheduled_action', [], 'sureforms', true );
45 }
46 }
47
48 /**
49 * Unschedule any action.
50 *
51 * @param string $hook Event hook name.
52 * @since 0.0.2
53 * @return void
54 */
55 public static function unschedule_events( $hook ) {
56 as_unschedule_all_actions( $hook );
57 }
58
59 }
60