An easy to use fluent wrapper for the WordPress Settings API.
PHP 5.3+
Below is an example.
$settings = Refactored_Settings_0_5_0::withKey('my_settings')
->version('1.0');
$section = Refactored_Settings_Section_0_5_0::withKey('general')
->name('Sample Section')
->description('A short description.')
->addFields(array(
Refactored_Settings_Field_0_5_0::withKey('name')
->type('text')
->name('Field Name')
->description('The name of a custom field.')
->defaultValue('custom'),
Refactored_Settings_Field_0_5_0::withKey('enabled')
->type('checkbox')
->name('Enabled')
->description('If the feature should be enabled.')
->defaultValue(false),
));
$settings->addSection($section);
$settings->init();
You should now have a fully functioning settings page with all the options you've specified. You'll also be able to access your settings:
$settings->general->enabled->getValue();
To avoid possible conflicts with plugins using different versions, class names have the version number appended.
Please be aware this project is still in development and may rapidly change.
Various action hooks are provided for your convenience.
These hooks are related to the main settings class which will be passed as an argument. Replace {$setting}
with your chosen key.
Fires before the setting is initialized. Useful for adding sections on the fly.
Fires after the setting is initialized
Print to settings page before the form
Print to settings page after the form
If a plugin file is specified, this is fired upon activation
If a plugin file is specified, this is fired upon deactivation
These hooks are related to the settings section class which will be passed as an argument. Replace {$setting}
and {$section}
with their relative keys.
Fires before the section is initialized. Useful for adding fields on the fly.
Fires after the section is initialized
These hooks are related to the settings field class which will be passed as an argument. Replace {$setting}
, {$section}
, and {$field}
with their relative keys.
Fires before the field is initialized
Fires after the field is initialized