Your plugin includes a boilerplate settings class that you can use to easily add a new settings to your plugin. It’s located at plugin-dir/classes/Settings.php
.
@Add A New Setting
Here we are adding a setting named ‘setting1’ using annotations.
/**
* ...
* @Wordpress\Options\Field( name="setting1", type="text", title="Setting 1", default="Hello Dollie." )
*/
class Settings extends \MWP\Framework\Plugin\Settings
@Example Code
The following code demonstrates how to retrieve a setting from your plugin code.
use VendorName\PackageName\Plugin;
$plugin = Plugin::instance();
$setting_value = $plugin->getSetting( 'setting1' );
if ( $setting_value == 'Hello Dollie.' ) {
/* Manually save a new setting */
$plugin->setSetting( 'setting2', 'Hello Dandy.' );
$plugin->getSettings()->saveSettings();
}