A WordPress helper class for managing plugin options.
composer require wp-forge/wp-options
<?php
use WP_Forge\Options\Options;
$options = new Options('my_plugin_options');
// Pass the option name and option value as parameters.
$options->set('name', 'value');
<?php
use WP_Forge\Options\Options;
$options = new Options('my_plugin_options');
// Pass the option name and a default value as parameters.
// If a default value is not provided, `null` will be the default return value.
$options->get('name', 'default');
<?php
use WP_Forge\Options\Options;
$options = new Options('my_plugin_options');
// Pass the option name to be deleted as a parameter.
$options->delete('name');
<?php
use WP_Forge\Options\Options;
$options = new Options('my_plugin_options');
// Pass the option name as a parameter.
$options->has('name');
By default, options will save automatically on the shutdown
hook.
However, if you'd like to force a save, you can do it like this:
<?php
use WP_Forge\Options\Options;
$options = new Options('my_plugin_options');
// Pass the option name and option value as parameters
$options->save();