File: /var/www/html/wp-content/plugins/allspice/includes/cron.php
<?php
// includes/cron.php
if (!defined('ABSPATH')) exit;
define('ALLSPICE_CRON_HOOK', 'allspice_cron_sync');
function allspice_cron_schedules($schedules): array {
if (!isset($schedules['allspice_12h'])) $schedules['allspice_12h'] = array('interval' => 12 * HOUR_IN_SECONDS, 'display' => 'Allspice (12 hours)');
return $schedules;
}
add_filter('cron_schedules', 'allspice_cron_schedules');
function allspice_activate_plugin(): void {
if (!wp_next_scheduled(ALLSPICE_CRON_HOOK)) wp_schedule_event(time() + 300, 'allspice_12h', ALLSPICE_CRON_HOOK);
}
function allspice_deactivate_plugin(): void {
$t = wp_next_scheduled(ALLSPICE_CRON_HOOK);
if ($t) wp_unschedule_event($t, ALLSPICE_CRON_HOOK);
}
function allspice_cron_refresh(): void {
$rb = allspice_refresh_buttons_cache(false);
if (empty($rb['ok'])) {
allspice_opt_update(array('cache_last_error' => (string)($rb['error'] ?? 'Unknown error')));
}
$rr = allspice_refresh_recipes_cache(false);
if (empty($rr['ok'])) {
allspice_opt_update(array('recipes_last_error' => (string)($rr['error'] ?? 'Unknown error')));
}
$rtp = allspice_refresh_theme_policies_cache(false);
if (empty($rtp['ok'])) {
allspice_opt_update(['theme_policies_last_error' => (string)($rtp['error'] ?? 'Unknown error')]);
}
}
add_action(ALLSPICE_CRON_HOOK, 'allspice_cron_refresh');