| 1 |
<?php |
| 2 |
namespace StoreEngine; |
| 3 |
|
| 4 |
use StoreEngine\Schedules\Order; |
| 5 |
use StoreEngine\Utils\Geolocation; |
| 6 |
use StoreEngine\Classes\LogCleanup; |
| 7 |
use StoreEngine\Classes\EmailLogCleanup; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
class Schedule { |
| 14 |
|
| 15 |
public static function init() { |
| 16 |
Order::init(); |
| 17 |
|
| 18 |
add_action( 'action_scheduler_ensure_recurring_actions', [ __CLASS__, 'register_recurring_actions' ] ); |
| 19 |
add_action( 'storeengine/geolocation/maxmind/db-update', [ Geolocation::class, 'update_maxmind_db' ] ); |
| 20 |
add_action( 'storeengine/logs/auto_cleanup', [ LogCleanup::class, 'execute_cleanup' ] ); |
| 21 |
add_action( 'storeengine/email_log/auto_cleanup', [ EmailLogCleanup::class, 'execute_cleanup' ] ); |
| 22 |
} |
| 23 |
|
| 24 |
public static function register_recurring_actions() { |
| 25 |
if ( ! function_exists( 'as_schedule_recurring_action' ) || ! function_exists( 'as_schedule_single_action' ) ) { |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
$gmt_offset = get_option( 'gmt_offset' ); |
| 30 |
$offset_hours = ( $gmt_offset > 0 ? '-' : '+' ) . absint( $gmt_offset ) . ' hours'; |
| 31 |
$tomorrow_6am = strtotime( 'tomorrow 06:00 am ' . $offset_hours ); |
| 32 |
|
| 33 |
$tomorrow_2am = strtotime( 'tomorrow 02:00 am ' . $offset_hours ); |
| 34 |
$tomorrow_3am = strtotime( 'tomorrow 03:00 am ' . $offset_hours ); |
| 35 |
|
| 36 |
as_schedule_recurring_action( $tomorrow_6am, 15 * DAY_IN_SECONDS, 'storeengine/geolocation/maxmind/db-update', [], 'storeengine', true ); |
| 37 |
|
| 38 |
as_schedule_recurring_action( $tomorrow_2am, DAY_IN_SECONDS, 'storeengine/logs/auto_cleanup',[], 'storeengine', true ); |
| 39 |
as_schedule_recurring_action( $tomorrow_3am, DAY_IN_SECONDS, 'storeengine/email_log/auto_cleanup', [], 'storeengine', true ); |
| 40 |
} |
| 41 |
} |
| 42 |
|