wp-launchpad/options

There is no license information available for the latest version (v3.1.0) of this package.

Options library for Launchpad

v3.1.0 2024-12-15 20:23 UTC

README

This library offers OOP facades to work with options and transients in WordPress.

Install

Just run the command composer require wp-launchpad/options

Note: It is easier to work with that library using the Launchpad framework.

Options

Options are a way to save a simple and light value in WordPress.

To use options with that library you need first to instantiate the class and provide it a prefix:

$options = new \LaunchpadOptions\Options('my_prefix');

Note: By convention your prefix should be your plugin or theme name.

Once this is done then you can directly access, update or delete options using the following API:

Site options

Site options are a way to save a simple and light value in WordPress just as regular options. However, the main difference resides in the fact in case of a multisite it will be present at the level of the website and not at the level from the network.

To use options with that library you need first to instantiate the class and provide it a prefix:

$options = new \LaunchpadOptions\SiteOptions('my_prefix');

Note: By convention your prefix should be your plugin or theme name.

Once this is done then you can directly access, update or delete options using the following API:

Transients

Transients are a way to save simple and light value but at the difference of options they expire after a certain time.

To use transients with that library you need first to instantiate the class and provide it a prefix:

$transients = new \LaunchpadOptions\Transients('my_prefix');

Note: By convention your prefix should be your plugin or theme name.

Once this is done then you can directly access, update or delete transients using the following API:

Settings

Settings are a way to easily save configurations for a plugin or a theme.

The advantage compared to options is that it is possible to mass update them or export them in one time.

To use settings with that library you need first to instantiate the class and provide it a prefix:

$settings = new \LaunchpadOptions\Settings(new \LaunchpadOptions\Options('my_prefix'), 'my_settings_prefix');

Note: By convention your prefix should be your plugin or theme name.

Once this is done then you can directly access, update or delete settings using the following API:

Set

Sets are a way to easily interact with array data coming from an option.

To use set with that library you need first to instantiate the class and provide it a prefix:

$set = new \LaunchpadOptions\Set([
    'key' => 'value'
], 'my_prefix');

Note: The prefix is actually important for filters within the class.

Once this is done then you can directly access, update or delete values within the set using the following API:

Note: The key difference between settings and sets is that Settings handle the saving in the database themselves when Set won't.