CMS Framework - v2.2.2
Settings
The Settings module provides a lightweight, application‑wide key–value store with:
- Declarative registration of settings (with defaults, types, and sanitization callbacks)
- Simple helpers to retrieve and update values
- Database persistence in a dedicated
settingstable - A filter hook so packages and modules can register settings from anywhere
Settings Guides
- Getting Started — Quick intro and first setting
- Registering Settings — Define defaults, types, and sanitizers
- Retrieving and Updating — Read and write values at runtime
- Sanitization and Types — Ensure clean, typed input
- Hooks and Events —
ap.settings.registeredSettingsfilter - Database and Migrations — Storage schema and considerations
- settings/Site Settings — Built-in
site.*settings and the WP-shape/api/v1/settings/siteendpoint (2.0.0)
Overview
Settings are discovered via a filter and stored in the database. You register settings during boot, then read and write them anywhere in your app.
Quick Example
use function apRegisterSetting;
use function apGetSetting;
use function apUpdateSetting;
// Register during boot (e.g., a service provider)
apRegisterSetting(
key: 'site.title',
defaultValue: 'My Site',
callback: fn ($value) => trim((string) $value),
type: 'string'
);
// Retrieve (uses stored value, registered default, or explicit fallback)
$title = apGetSetting('site.title', 'Fallback Title');
// Update (value will be sanitized using the registered callback)
apUpdateSetting('site.title', ' New Title ');
See the guides above for more details and patterns.