Download the PHP package wordpressvn/wp-settings without Composer
On this page you can find all versions of the php package wordpressvn/wp-settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wordpressvn/wp-settings
More information about wordpressvn/wp-settings
Files in wordpressvn/wp-settings
Package wp-settings
Short Description Handy wrapper to make creating WordPress settings pages a breeze.
License GPL-2.0
Informations about the package wp-settings
WP Settings
This package aims to make it easier to create settings pages for WordPress plugins. Typically, you would use the Settings API or write something custom. While the Settings API works, there is still quite a lot to set up. You still need to write the HTML for your options for example. And it gets quite complicated if you want to add tabs and tab-sections. See this comparison.
Installation
Usage
Basic example
Creating the settings instance
By default, the page slug is created by sanitizing the title. You may pass a specific slug as the second parameter of the constructor.
Other methods for this class:
Tabs
Tabs are only displayed when there is more then one.
Sections
You can call the add_section
method from an instance of Tab
. You can also call it from the WPSettings
instance. It will then be added to the last created Tab
.
If you want sections to be displayed as submenu-items, you can do:
Note that this only has an effect when you have more then one as_link
section.
Options
To add an option, you either call the add_option
method from an instance of Section
. You may also call add_option
from the WPSettings
instance. The option will then be added to the last created section.
Text
In addition to name
and label
, you can also pass type
. This makes it possible to set the input type to, for example, password or number.
Textarea
You may also set the cols
and rows
attributes.
Checkbox
Select
Select2
WP Editor
Code Editor
Color
Media
For an image specific, you can use:
For video specific, you can use:
Validation
You are able to validate an option. You may pass a callback and a feedback message. You can pass multiple validation rules.
Sanitization
You may pass a sanitization callback.
Options array structure
By default, the options are stored as a one level array:
However, you can add tab and/or section levels in this structure.
Which would result in:
Adding a custom option type
To add an custom option type, you can use the wp_settings_option_type_map
filter.
You will need to create a class for your custom option type.
Once registered, you can then use your option type like so:
Contributors
License
MIT. Please see the License File for more information.