cron = $cron; $this->inspector = $inspector ?? new ABJ_404_Solution_ScheduledEventInspector(); } /** * Whether this site has proved, now or earlier, that WP-Cron is not * dispatching. Reads the in-request cron store; callers that cross * requests refresh the store reads first. * * @param int|null $observedEventTimestamp A stored event the caller has * already read through the scheduler (its own queued work). It is one * more stored event, judged by the same threshold as the rest, so no * caller keeps a private overdue check beside this one. */ public function isProven(?int $observedEventTimestamp = null): bool { if (!function_exists('get_option')) { return false; } $record = ABJ_404_Solution_OptionShapeRead::arrayValue(self::OPTION, null); if (is_array($record) && ($record['version'] ?? null) === 1) { return true; } $oldest = $this->inspector->oldestStoredEventTimestamp(); if ($observedEventTimestamp !== null) { $oldest = $oldest === null ? $observedEventTimestamp : min($oldest, $observedEventTimestamp); } $now = $this->cron->now(); if ($oldest === null || $now - $oldest <= self::OVERDUE_SECONDS) { return false; } if (function_exists('update_option')) { update_option(self::OPTION, array( 'version' => 1, 'observed_at' => $now, 'event_timestamp' => $oldest, ), false); } return true; } /** * WordPress boundary on `init`: a request WordPress dispatched as cron * proves dispatch works again, so the recorded stall is retired. */ public static function observeRequest(): void { if (!function_exists('wp_doing_cron') || !wp_doing_cron() || !function_exists('delete_option')) { return; } delete_option(self::OPTION); } }