, show_name:bool, ack:bool, active:bool}> keyed by form ID */ public static function forms(): array { $raw = get_option(self::OPTION, []); $items = is_array($raw) && is_array($raw['items'] ?? null) ? $raw['items'] : []; $out = []; foreach ($items as $id => $def) { $clean = is_array($def) ? FormDefinitions::normalize((int) $id, $def) : null; if ($clean !== null) { $out[(int) $id] = $clean; } } return $out; } /** @return array|null an ACTIVE form of this site, or null (missing, inactive or from another site) */ public static function activeForm(int $id): ?array { $f = self::forms()[$id] ?? null; return $f !== null && $f['active'] ? $f : null; } /** @param array $in untrusted administrator input @return string '' on success or a problem code */ public static function save(int $id, array $in): string { $raw = get_option(self::OPTION, []); $next = is_array($raw) ? max(1, (int) ($raw['next'] ?? 1)) : 1; $forms = self::forms(); $isNew = $id <= 0; if ($isNew) { $id = $next; } elseif (!isset($forms[$id])) { return 'unknown'; } $clean = FormDefinitions::normalize($id, $in); if ($clean === null) { return 'invalid'; } $others = $forms; unset($others[$id]); $problem = FormDefinitions::limitProblem($others, $clean, $isNew); if ($problem !== '') { return $problem; } $forms[$id] = $clean; update_option(self::OPTION, ['next' => max($next, $id + 1), 'items' => $forms], false); return ''; } public static function delete(int $id): bool { $forms = self::forms(); if (!isset($forms[$id])) { return false; } unset($forms[$id]); $raw = get_option(self::OPTION, []); update_option(self::OPTION, ['next' => is_array($raw) ? max(1, (int) ($raw['next'] ?? 1)) : 1, 'items' => $forms], false); return true; } public static function retentionDays(): int { return max(self::RETENTION_MIN, min(self::RETENTION_MAX, (int) get_option(self::RETENTION_OPTION, self::RETENTION_DEFAULT))); } public static function store(Plugin $plugin): SubmissionStore { return new SubmissionStore($plugin->db, wp_salt('auth')); } }