Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

WordPress Options

A WordPress helper class for managing plugin options.

Installation

composer require wp-forge/wp-options

Usage

Setting Options

<?phpuseWP_Forge\Options\Options;
$options = newOptions('my_plugin_options');
// Pass the option name and option value as parameters.$options->set('name', 'value');

Getting Options

<?phpuseWP_Forge\Options\Options;
$options = newOptions('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');

Deleting Options

<?phpuseWP_Forge\Options\Options;
$options = newOptions('my_plugin_options');
// Pass the option name to be deleted as a parameter.$options->delete('name');

Checking if an Option Exists

<?phpuseWP_Forge\Options\Options;
$options = newOptions('my_plugin_options');
// Pass the option name as a parameter.$options->has('name');

Saving Options

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:

<?phpuseWP_Forge\Options\Options;
$options = newOptions('my_plugin_options');
// Pass the option name and option value as parameters$options->save();

About

A WordPress helper class for managing plugin options.

Resources

Code of conduct

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages