Skip to content

Settings API

Wireframe\Settings is the primary API for reading and writing saved field values from anywhere in your plugin. Every call takes your plugin’s option_key as the first argument, so multiple plugins sharing the framework can never collide on storage.

use Wireframe\Settings;
$opt = 'my_plugin_settings'; // matches what you passed to App::boot()
Settings::get($opt, 'field_id'); // any value, with dot notation
Settings::get($opt, 'field_id', 'fallback'); // with default
Settings::get($opt, 'repeater.0.subfield'); // dot notation into repeaters
MethodAlways returns
Settings::bool($opt, $key, $default = false)bool
Settings::int($opt, $key, $default = 0)int
Settings::float($opt, $key, $default = 0.0)float
Settings::string($opt, $key, $default = '')string
Settings::array($opt, $key, $default = [])array
Settings::json($opt, $key, $default = null)decoded JSON

Coercion is best-effort: string '1' becomes bool true, string '3.14' becomes float 3.14, etc. Use these in business code so you don’t have to defensively cast at every call site.

Settings::set($opt, 'site_name', 'New Name');
Settings::toggle($opt, 'notifications');
Settings::increment($opt, 'view_count');
Settings::decrement($opt, 'credits', 5);
Settings::push($opt, 'allowed_ips', '10.0.0.1');
Settings::forget($opt, 'api_key');
MethodNotes
set($opt, $key, $value)Replace the value at $key.
toggle($opt, $key)Flip a boolean.
increment($opt, $key, $by = 1)Bump a numeric value.
decrement($opt, $key, $by = 1)Drop a numeric value.
push($opt, $key, $value)Append to an array value.
forget($opt, $key)Remove a key entirely.
Settings::has($opt, 'api_key'); // key exists and value is not null
Settings::exists($opt); // any settings saved at all
Settings::filled($opt, 'site_name', 'fallback'); // non-empty value or fallback
Settings::only($opt, 'site_name', 'email'); // associative array — just these keys
Settings::except($opt, 'api_key', 'password'); // associative array — everything except
Settings::all($opt); // raw saved values
Settings::resolved($opt); // saved values merged with config defaults

all() returns only the keys that have been explicitly saved. resolved() is what the React app sees — every declared field, with its default filled in where no saved value exists.

// Run a callback only if the key has a value, return what the callback returns.
$result = Settings::when($opt, 'api_key', fn($key) => initService($key));
// Transform a value through a callback before returning.
$color = Settings::transform($opt, 'color', fn($c) => ltrim($c, '#'));
// Get a value, or set + return a default if missing.
$counter = Settings::getOrSet($opt, 'counter', 0);
// Get a value then forget the key (one-shot tokens, flash data).
$token = Settings::pull($opt, 'temp_token');

Because every method takes $opt first, the facade has no global state to coordinate. Two plugins on the same site can each use Settings::get() with their own keys without seeing each other’s data:

$themeOptions = Settings::get('my_theme', 'palette');
$pluginOptions = Settings::get('my_plugin', 'features');