$schedules */ public function schedules(array $schedules): array { $schedules[self::SCHEDULE] = [ 'display' => __('Sarcio pull refresh', 'sarcio'), 'interval' => max(60, (int) Options::get('pull_refresh_sec')), ]; return $schedules; } /** Claim the schedule while the direct transport is in use; drop it otherwise. */ public function reconcileSchedule(): void { $wanted = Options::serverTransport() === 'pull'; $next = wp_next_scheduled(self::HOOK); if ($wanted && !$next) { wp_schedule_event(time() + 60, self::SCHEDULE, self::HOOK); } elseif (!$wanted && $next) { wp_unschedule_event((int) $next, self::HOOK); } } /** One pull now, recording the outcome. Safe to call from a request, cron or WP-CLI. */ public function run(): bool { $transport = $this->plugin->shim()?->transport(); if (!$transport instanceof PullTransport) { return false; } $ok = $transport->pull(); update_option(self::STATUS_OPTION, [ 'at' => time(), 'ok' => $ok, 'routes' => $ok ? count($transport->routes()) : null, ], false); return $ok; } /** @return array{at:int,ok:bool,routes:int|null}|array{} */ public static function status(): array { $value = get_option(self::STATUS_OPTION, []); return is_array($value) && isset($value['at']) ? $value : []; } public static function unschedule(): void { $next = wp_next_scheduled(self::HOOK); if ($next) { wp_unschedule_event((int) $next, self::HOOK); } } }