abilities
3 weeks ago
admin
3 months ago
ai-form-builder
1 month ago
blocks
2 months ago
compatibility
3 weeks ago
database
3 weeks ago
email
3 weeks ago
fields
3 weeks ago
global-settings
1 month ago
lib
1 month ago
migrator
2 months ago
page-builders
3 weeks ago
payments
3 weeks ago
single-form-settings
2 months ago
traits
2 months ago
activator.php
1 year ago
admin-ajax.php
2 months ago
background-process.php
9 months ago
create-new-form.php
3 months ago
duplicate-form.php
3 months ago
entries.php
3 weeks ago
events-scheduler.php
2 years ago
export.php
3 months ago
field-validation.php
3 weeks ago
form-restriction.php
2 months ago
form-styling.php
1 month ago
form-submit.php
5 days ago
forms-data.php
5 months ago
frontend-assets.php
5 days ago
generate-form-markup.php
1 week ago
gutenberg-hooks.php
1 week ago
helper.php
5 days ago
learn.php
4 months ago
onboarding.php
2 months ago
post-types.php
1 week ago
rest-api.php
1 week ago
smart-tags.php
5 days ago
submit-token.php
4 months ago
translatable.php
1 month ago
updater-callbacks.php
3 weeks ago
updater.php
3 weeks ago
events-scheduler.php
60 lines
| 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 |