*/ public static function defaults() { return array( 'setup_complete' => false, 'schedule_enabled' => false, 'schedule_time' => '08:00', // HH:MM, local to 'timezone'. 'timezone' => '', // IANA id; '' => wp_timezone_string() at read time. 'recipients' => array(), // Daily report recipients (validated emails). 'critical_recipients' => array(), // Critical alert recipients. 'send_all_clear' => true, // Daily report even with no changes. 'detail_level' => 'standard', // 'summary' | 'standard'. 'alert_cooldown_hours' => 24, 'retention_days' => 90, // PRD 5.1 default; PRD 14 suggests 30 — founder to confirm. 'delete_data_on_uninstall' => false, 'max_report_attempts' => 3, 'recipient_consent' => array(), // Receipt set by setup: version, at (UTC), user_id. 'feed_enabled' => false, // Live vulnerability feed (anonymous HTTPS GET to the plugin author's API). Opt-in only. 'vuln_alert_mode' => 'daily', // 'daily' | 'weekly' | 'off': emails about newly found vulnerabilities. 'vuln_recipients' => array(), // Empty => report recipients, then the site admin email. ); } public static function ensure_defaults() { if ( false === get_option( self::OPTION, false ) ) { add_option( self::OPTION, self::defaults(), '', 'no' ); } } /** @return array */ public static function all() { $stored = get_option( self::OPTION, array() ); $merged = array_merge( self::defaults(), is_array( $stored ) ? $stored : array() ); if ( '' === $merged['timezone'] ) { $merged['timezone'] = self::site_timezone(); } return $merged; } /** @return mixed */ public static function get( $key ) { $all = self::all(); return array_key_exists( $key, $all ) ? $all[ $key ] : null; } /** * Merge and persist. Callers are responsible for sanitizing values first. * * @param array $values */ public static function update( array $values ) { $current = get_option( self::OPTION, array() ); $current = is_array( $current ) ? $current : array(); $allowed = array_intersect_key( $values, self::defaults() ); update_option( self::OPTION, array_merge( self::defaults(), $current, $allowed ), 'no' ); } public static function site_timezone() { $tz = function_exists( 'wp_timezone_string' ) ? wp_timezone_string() : 'UTC'; // wp_timezone_string() may return an offset like '+13:00'; keep it, DateTimeZone accepts it. return $tz ? $tz : 'UTC'; } }