Download the PHP package oberonlai/wp-option without Composer
On this page you can find all versions of the php package oberonlai/wp-option. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download oberonlai/wp-option
More information about oberonlai/wp-option
Files in oberonlai/wp-option
Package wp-option
Short Description Adding option page for WordPress.
License MIT
Homepage https://github.com/oberonlai/wp-option
Informations about the package wp-option
WP Option v1.0
Simple WordPress class for settings api modifed from boo-settings-helper
Requirements
Installation
Install with composer
Run the following in your terminal to install with Composer.
WP Option PSR-4 autoloading and can be used with the Composer's autoloader. Below is a basic example of getting started, though your setup may be different depending on how you are using Composer.
See Composer's basic usage guide for details on working with Composer and autoloading.
Basic Usage
Below is a basic example of setting up a simple option page.
Usage
To create a option, first instantiate an instance of Option
. The class takes one argument, which is an plugin prefix. All of the options' name will add this prefix.
After instantiating the above option, you have to add settings menu and tab.
Menu
Firstly, we need to add admin menu to our admin page.
You have to set option to true if you want to add menu under the settings menu.
Tab
You have to add one tab at least. The fields are placed in tab.
Avaiable fields
Fields list
- Text
- URL
- Number
- Color
- Textarea
- Radio Button
- Select
- HTML
- Checkbox
- Multi Select
- Related
- Password
- File
- Media Upload
Common params of fields:
- id - (string) Field ID. Use get_option( $plugin-prefix. 'field_id' ) to get value.
- label - (string) Field name.
- desc - (string) Field description.
- placeholder - (string) Field placeholder.
- default - (string) Select, checkbox, radio default option.
- options - (array) Select, radio, multicheck options.
- callback - (callback) Function name to be used to render field.
- sanitize_callback (callback) Function name to be used for sanitization
- show_in_rest - (Boolean) Show in REST API.
- class - (string) - Field css class name. Separate more classes with space.
- size - (string) - Field size. Options for small, regular, and large.
Text
There are three arguments. First is the tab ID, second is text field params, and last is callback function of render field.
With render callback function:
URL
Number
Color
Textarea
Radio Button
Select
HTML
Add static html in table row.
Checkbox
Checkboxes
Posts
Add specific post type. The third params is the name of custom post type.
Password
File Uploader
Media Uploader
Render field
You can use callback function when add field to render the field.
Add links in plugins list
You can add links below the plugin name in list.
Retrive field's value
You can use WordPress get_option() to get value. Don't forget the prefix name of field id. For example::
If you want to retrive field value of 'my_text_field', use code below: