|null */ private static ?array $cache = null; /** * Get all settings (merged over defaults). * * @return array */ public static function all(): array { if ( null === self::$cache ) { $stored = get_option( self::OPTION, array() ); self::$cache = is_array( $stored ) ? array_merge( Migrator::default_settings(), $stored ) : Migrator::default_settings(); } return self::$cache; } /** * Get a single setting. * * @param string $key Setting key. * @param mixed $default Fallback. * @return mixed */ public static function get( string $key, $default = null ) { $all = self::all(); return $all[ $key ] ?? $default; } /** * Persist the full settings array. * * @param array $settings Settings. */ public static function save( array $settings ): void { update_option( self::OPTION, $settings, false ); self::$cache = null; } /** * Flush the cache (after external writes). */ public static function flush(): void { self::$cache = null; } /** * Has a detector been learned as "active" for this site? * * @param string $detector Detector id. * @return bool */ public static function detector_active( string $detector ): bool { $detectors = (array) self::get( 'detectors', array() ); return in_array( $detector, $detectors, true ); } /** * Mark a detector active (Auto-Config self-learning). Persists only on change. * * @param string $detector Detector id. */ public static function learn_detector( string $detector ): void { // Respect the Auto-Config toggle: when off, freeze the learned set. if ( ! self::get( 'auto_config', 1 ) ) { return; } $all = self::all(); $detectors = (array) ( $all['detectors'] ?? array() ); if ( in_array( $detector, $detectors, true ) ) { return; } $detectors[] = $detector; $all['detectors'] = array_values( array_unique( $detectors ) ); self::save( $all ); } /** * Current cache-buster timestamp (appended to served URLs). * * @return int */ public static function buster(): int { return (int) get_option( 'easyfonts_cache_buster', 0 ); } /** * Bump the cache-buster (after re-optimisation / purge). */ public static function bump_buster(): void { update_option( 'easyfonts_cache_buster', time(), false ); } }