Download the PHP package screenfeed/autowpoptions without Composer
On this page you can find all versions of the php package screenfeed/autowpoptions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download screenfeed/autowpoptions
More information about screenfeed/autowpoptions
Files in screenfeed/autowpoptions
Package autowpoptions
Short Description Manage a set of WordPress options.
License GPL-2.0
Homepage https://github.com/Screenfeed/autowpoptions
Informations about the package autowpoptions
AutoWPOptions
Allows to manage a set of options in WordPress.
Requires php 5.4 and WordPress 4.4.
What you will be able to do
- Decide if your set of options is network-wide or site-wide in a multisite environment,
- Obviously, get/set/delete values,
- Provide default and reset values,
- Cast, sanitize, and validate values automatically,
- Create an upgrade process.
How to install
With composer:
How to use
Create one class that extends Sanitization\AbstractSanitization. This class will contain the following:
Default values
Required. They are used when an option has no value yet. Their type is used to decide how to cast the values.
Reset values
Optional. Reset values are used if the whole set of options does not exist yet: sometimes you may want them to be different from the default values. Default values are used for the missing reset values.
You could also use them in a "Reset Options" process for example.
A sanitization method
Required. It is run for each option, when getting/updating it.
A validation method
Required (but can simply return the entry if not needed). It is run once for all options on update. It allows to edit some values, depending on others for example.
Two keywords as class properties
Required. They are used in hook names.
Example
How to create an option that is stored as an array in the WordPress' options table:
- The option name is
myplugin_settings
, - The current plugin version is
2.3
, - The option must be network-wide on a multisite install.
The MyOptionsSanitization
class:
- The two keywords
myplugin
andsettings
are used in hook names, like the filterget_myplugin_settings_foobar
.
An "upgrade process"?
The plugin version used when instanciating MyOptionsSanitization
is stored in the option and can be used in a future plugin release for an upgrade process.
For example:
Reserved keyworks
Don't use the following keywords as option keys, they are used internally:
- cached
- version
Extending
You may want to store your options elsewhere than the WordPress' options table, maybe in configuration file (heck, why not). This package is built in such a way that it is possible.
To do so, you need to create a class that will replace Screenfeed\AutoWPOptions\Storage\WpOption
, and implement Screenfeed\AutoWPOptions\Storage\StorageInterface
.