| 1 |
<?php |
| 2 |
/** |
| 3 |
* Cron controller |
| 4 |
* |
| 5 |
* @since 6.3.2 |
| 6 |
* |
| 7 |
* @package Formidable |
| 8 |
*/ |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
die( 'You are not allowed to call this page directly.' ); |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Class FrmCronController |
| 16 |
*/ |
| 17 |
class FrmCronController { |
| 18 |
|
| 19 |
/** |
| 20 |
* Gets all cron events. |
| 21 |
* |
| 22 |
* @since 6.3.2 |
| 23 |
* |
| 24 |
* @return string[] |
| 25 |
*/ |
| 26 |
private static function get_events() { |
| 27 |
return array( |
| 28 |
'formidable_send_usage' => 'weekly', |
| 29 |
'frm_daily_event' => 'daily', |
| 30 |
'frm_payment_cron' => 'daily', |
| 31 |
); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Schedules cron events. |
| 36 |
* |
| 37 |
* @since 6.7 |
| 38 |
* |
| 39 |
* @return void |
| 40 |
*/ |
| 41 |
public static function schedule_events() { |
| 42 |
$events = self::get_events(); |
| 43 |
|
| 44 |
// These are scheduled in another place. |
| 45 |
unset( $events['formidable_send_usage'] ); |
| 46 |
unset( $events['frm_payment_cron'] ); |
| 47 |
|
| 48 |
foreach ( $events as $event => $recurrence ) { |
| 49 |
if ( ! wp_next_scheduled( $event ) ) { |
| 50 |
wp_schedule_event( time(), $recurrence, $event ); |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Removes all cron events. |
| 57 |
* |
| 58 |
* @since 6.3.2 |
| 59 |
* |
| 60 |
* @return void |
| 61 |
*/ |
| 62 |
public static function remove_crons() { |
| 63 |
$events = self::get_events(); |
| 64 |
|
| 65 |
foreach ( $events as $event => $recurrence ) { |
| 66 |
$timestamp = wp_next_scheduled( $event ); |
| 67 |
|
| 68 |
if ( false !== $timestamp ) { |
| 69 |
wp_unschedule_event( $timestamp, $event ); |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
|