PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.7
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.7
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / Libraries / action-scheduler / classes / ActionScheduler_RecurringActionScheduler.php

ActionScheduler_RecurringActionScheduler.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.7, at app/Services/Libraries/action-scheduler/classes/ActionScheduler_RecurringActionScheduler.php

82 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class ActionScheduler_RecurringActionScheduler
5 *
6 * This class ensures that the `action_scheduler_ensure_recurring_actions` hook is triggered on a daily interval. This
7 * simplifies the process for other plugins to register their recurring actions without requiring each plugin to query
8 * or schedule actions independently on every request.
9 */
10 class ActionScheduler_RecurringActionScheduler {
11
12 /**
13 * @var string The hook of the scheduled recurring action that is run to trigger the
14 * `action_scheduler_ensure_recurring_actions` hook that plugins should use. We can't directly have the
15 * scheduled action hook be the hook plugins should use because the actions will show as failed if no plugin
16 * was actively hooked into it.
17 */
18 private const RUN_SCHEDULED_RECURRING_ACTIONS_HOOK = 'action_scheduler_run_recurring_actions_schedule_hook';
19
20 /**
21 * Initialize the instance. Should only be run on a single instance per request.
22 *
23 * @return void
24 */
25 public function init(): void {
26 add_action( self::RUN_SCHEDULED_RECURRING_ACTIONS_HOOK, array( $this, 'run_recurring_scheduler_hook' ) );
27 if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
28 add_action( 'action_scheduler_init', array( $this, 'schedule_recurring_scheduler_hook' ) );
29 }
30 }
31
32 /**
33 * Schedule the recurring `action_scheduler_ensure_recurring_actions` action if not already scheduled.
34 *
35 * @return void
36 */
37 public function schedule_recurring_scheduler_hook(): void {
38 if ( false === wp_cache_get( 'as_is_ensure_recurring_actions_scheduled' ) ) {
39 if ( ! as_has_scheduled_action( self::RUN_SCHEDULED_RECURRING_ACTIONS_HOOK ) ) {
40 as_schedule_recurring_action(
41 time(),
42 DAY_IN_SECONDS,
43 self::RUN_SCHEDULED_RECURRING_ACTIONS_HOOK,
44 [],
45 'ActionScheduler',
46 true,
47 20
48 );
49 }
50 wp_cache_set( 'as_is_ensure_recurring_actions_scheduled', true, HOUR_IN_SECONDS );
51 }
52 }
53
54 /**
55 * Trigger the hook to allow other plugins to schedule their recurring actions.
56 *
57 * @return void
58 */
59 public function run_recurring_scheduler_hook(): void {
60 /**
61 * Fires to allow extensions to verify and ensure their recurring actions are scheduled.
62 *
63 * This action is scheduled to trigger once every 24 hrs for the purpose of having 3rd party plugins verify that
64 * any previously scheduled recurring actions are still scheduled. Because recurring actions could stop getting
65 * rescheduled by default due to excessive failures, database issues, or other interruptions, extensions can use
66 * this hook to check for the existence of their recurring actions and reschedule them if necessary.
67 *
68 * Example usage:
69 *
70 * add_action('action_scheduler_ensure_recurring_actions', function() {
71 * // Check if the recurring action is scheduled, and reschedule if missing.
72 * if ( ! as_has_scheduled_action('my_recurring_action') ) {
73 * as_schedule_recurring_action( time(), HOUR_IN_SECONDS, 'my_recurring_action' );
74 * }
75 * });
76 *
77 * @since 3.9.3
78 */
79 do_action( 'action_scheduler_ensure_recurring_actions' );
80 }
81 }
82