PHPackages                             oberonlai/wp-option - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. oberonlai/wp-option

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

oberonlai/wp-option
===================

Adding option page for WordPress.

v1.0.5(4y ago)7662MITPHPPHP &gt;=7.2

Since Jun 29Pushed 4y ago1 watchersCompare

[ Source](https://github.com/oberonlai/wp-option)[ Packagist](https://packagist.org/packages/oberonlai/wp-option)[ Docs](https://github.com/oberonlai/wp-option)[ RSS](/packages/oberonlai-wp-option/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (7)Used By (0)

WP Option v1.0
==============

[](#wp-option-v10)

[![](https://camo.githubusercontent.com/b328e81ebcf16560cfbf650e4412b994b3b4a1689621f6e5c8618589caf75522/68747470733a2f2f6f6265726f6e6c61692e626c6f672f77702d636f6e74656e742f75706c6f6164732f776f726470726573732d616e642d636f6d706f7365722f776f726470726573732d616e642d636f6d706f7365722d31302e6a7067)](https://camo.githubusercontent.com/b328e81ebcf16560cfbf650e4412b994b3b4a1689621f6e5c8618589caf75522/68747470733a2f2f6f6265726f6e6c61692e626c6f672f77702d636f6e74656e742f75706c6f6164732f776f726470726573732d616e642d636f6d706f7365722f776f726470726573732d616e642d636f6d706f7365722d31302e6a7067)

> Simple WordPress class for settings api modifed from [boo-settings-helper](https://github.com/boospot/boo-settings-helper)

Requirements
------------

[](#requirements)

- PHP &gt;=7.2
- [Composer](https://getcomposer.org/)
- [WordPress](https://wordpress.org) &gt;=5.4

Installation
------------

[](#installation)

#### Install with composer

[](#install-with-composer)

Run the following in your terminal to install with [Composer](https://getcomposer.org/).

```
$ composer require oberonlai/wp-option

```

WP Option [PSR-4](https://www.php-fig.org/psr/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.

```
require __DIR__ . '/vendor/autoload.php';

use ODS\Option;

$prefix = 'plugin-prefix';

$books = new Option( $prefix );
```

See Composer's [basic usage](https://getcomposer.org/doc/01-basic-usage.md#autoloading) guide for details on working with Composer and autoloading.

Basic Usage
-----------

[](#basic-usage)

Below is a basic example of setting up a simple option page.

```
// Require the Composer autoloader.
require __DIR__ . '/vendor/autoload.php';

// Import PostTypes.
use ODS\Option;

$config = new Option( 'plugin-prefix' );
$config->addMenu();
$config->addTab();
$config->addText();
$config->register(); // Don't forget this.
```

Usage
-----

[](#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.

```
$config = new Option( 'plugin-prefix' );
```

After instantiating the above option, you have to add settings menu and tab.

### Menu

[](#menu)

Firstly, we need to add admin menu to our admin page.

```
$config->addMenu(
	array(
		'page_title' => __( 'Plugin Name Settings', 'plugin-name' ),
		'menu_title' => __( 'Plugin Name', 'plugin-name' ),
		'capability' => 'manage_options',
		'slug'       => 'plugin-name',
		'icon'       => 'dashicons-performance',
		'position'   => 10,
		'submenu'    => true,
		'parent'     => 'edit.php?post_type=event',
	)
);
```

You have to set option to true if you want to add menu under the settings menu.

```
$config->addMenu(
	array(
		'page_title' => __( 'Plugin Name Settings', 'plugin-name' ),
		'menu_title' => __( 'Plugin Name', 'plugin-name' ),
		'capability' => 'manage_options',
		'slug'       => 'plugin-name',
		'option'     => true
	)
);
```

### Tab

[](#tab)

You have to add one tab at least. The fields are placed in tab.

```
$config->addTab(
	array(
		array(
			'id'    => 'general_section',
			'title' => __( 'General Settings', 'plugin-name' ),
			'desc'  => __( 'These are general settings for Plugin Name', 'plugin-name' ),
		),
		array(
			'id'    => 'advance_section',
			'title' => __( 'Advanced Settings', 'plugin-name' ),
			'desc'  => __( 'These are advance settings for Plugin Name', 'plugin-name' )
		)
	)
);
```

Avaiable fields
---------------

[](#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.

```
array(
	'id'                => 'text_field_id',
	'label'             => __( 'Text Field', 'plugin-name' ),
	'desc'              => __( 'Some description of my field', 'plugin-name' ),
	'placeholder'       => 'This is Placeholder',
	'default'           => '',
	'options'           => array(),
	'callback'          => '',
	'sanitize_callback' => '',
	'show_in_rest'      => true,
	'class'             => 'my_custom_css_class',
	'size'              => 'regular',
),
```

### Text

[](#text)

There are three arguments. First is the tab ID, second is text field params, and last is callback function of render field.

```
$config->addText(
	'general_section',
	array(
		'id'                => 'text_field_id',
		'label'             => __( 'Hello World', 'plugin-name' ),
		'desc'              => __( 'Some description of my field', 'plugin-name' ),
		'placeholder'       => 'This is Placeholder',
		'show_in_rest'      => true,
		'class'             => 'my_custom_css_class',
		'size'              => 'regular',
	),
);
```

With render callback function:

```
$config->addText(
	'general_section',
	array(
		'id'    => 'text_field_id',
		'label' => __( 'Hello World', 'plugin-name' ),
	),
	function( $args ) {
		$html  = sprintf(
			'',
			$args['type'],
			$args['name'],
			$args['value'],
			'Placeholder from callback'
		);
		$html .= 'This field is generated with callback parameter';
		echo $html;
		unset( $html );
	}
);
```

### URL

[](#url)

```
$config->addUrl(
	'general_section',
	array(
		'id'    => 'url_field_id',
		'label' => __( 'URL Field', 'plugin-name' ),
	),
);
```

### Number

[](#number)

```
$config->addNumber(
	'general_section',
	array(
		'id'          => 'number_field_id',
		'label'       => __( 'Number Input', 'plugin-name' ),
		'placeholder' => __( 'Your Age here', 'plugin-name' ),
		'options'     => array(
			'min'  => 0,
			'max'  => 99,
			'step' => '1',
		),
	),
);
```

### Color

[](#color)

```
$config->addColor(
	'general_section',
	array(
		'id'    => 'color_field_id',
		'label' => __( 'Color Field', 'plugin-name' ),
	),
);
```

### Textarea

[](#textarea)

```
$config->addTextarea(
	'general_section',
	array(
		'id'          => 'textarea_field_id',
		'label'       => __( 'Textarea Input', 'plugin-name' ),
		'desc'        => __( 'Textarea description', 'plugin-name' ),
		'placeholder' => __( 'Textarea placeholder', 'plugin-name' ),
	),
);
```

### Radio Button

[](#radio-button)

```
$config->addRadio(
	'general_section',
	array(
		'id'      => 'radio_field_id',
		'label'   => __( 'Radio Button', 'plugin-name' ),
		'desc'    => __( 'A radio button', 'plugin-name' ),
		'options' => array(
			'radio_1' => 'Radio 1',
			'radio_2' => 'Radio 2',
			'radio_3' => 'Radio 3',
		),
		'default' => 'radio_2',
	),
);
```

### Select

[](#select)

```
$config->addSelect(
	'general_section',
	array(
		'id'      => 'select_field_id',
		'label'   => __( 'A Dropdown Select', 'plugin-name' ),
		'desc'    => __( 'Dropdown description', 'plugin-name' ),
		'default' => 'option_2',
		'options' => array(
			'option_1' => 'Option 1',
			'option_2' => 'Option 2',
			'option_3' => 'Option 3',
		),
		'default' => 'option_3',
	),
);
```

### HTML

[](#html)

Add static html in table row.

```
$config->addHtml(
	'general_section',
	array(
		'id'    => 'html',
		'label' => 'HTML',
		'desc'  => __( 'HTML area description. You can use any bold or other HTML elements.', 'plugin-name' ),
	),
);
```

### Checkbox

[](#checkbox)

```
$config->addCheckbox(
	'general_section',
	array(
		'id'    => 'checkbox_field_id',
		'label' => __( 'Checkbox', 'plugin-name' ),
		'desc'  => __( 'A Checkbox', 'plugin-name' ),
	),
);
```

### Checkboxes

[](#checkboxes)

```
$config->addCheckboxes(
	'general_section',
	array(
		'id'      => 'multi_field_id',
		'label'   => __( 'Checkboxes', 'plugin-name' ),
		'desc'    => __( 'A checkboxes', 'plugin-name' ),
		'options' => array(
			'multi_1' => 'Multi 1',
			'multi_2' => 'Multi 2',
			'multi_3' => 'Multi 3',
		),
		'default' => array(
			'multi_1' => 'multi_1',
			'multi_3' => 'multi_3',
		),
	),
);
```

### Posts

[](#posts)

Add specific post type. The third params is the name of custom post type.

```
$config->addPost(
	'general_section',
	array(
		'id'      => 'pages_field_id',
		'label'   => __( 'Pages Field Type', 'plugin-name' ),
		'desc'    => __( 'List of Pages', 'plugin-name' ),
	),
	'page' // post type
);
```

### Password

[](#password)

```
$config->addPassword(
	'general_section',
	array(
		'id'          => 'password_field_id',
		'label'       => __( 'Password Field', 'plugin-name' ),
		'desc'        => __( 'Password description', 'plugin-name' ),
		'placeholder' => __( 'Textarea placeholder', 'plugin-name' ),
	),
);
```

### File Uploader

[](#file-uploader)

```
$config->addFile(
	'general_section',
	array(
		'id'      => 'file_field_id',
		'label'   => __( 'File', 'plugin-name' ),
		'desc'    => __( 'File description', 'plugin-name' ),
		'options' => array(
			'btn' => 'Get it', // upload button text
		),
	),
);
```

### Media Uploader

[](#media-uploader)

```
$config->addMedia(
	'general_section',
	array(
		'id'      => 'media_field_id',
		'label'   => __( 'Media', 'plugin-name' ),
		'desc'    => __( 'Media', 'plugin-name' ),
		'type'    => 'media',
		'options' => array(
			'btn'       => __( 'Get the image', 'plugin-name' ),
			'width'     => 150,
			'max_width' => 150,
		),
	),
);
```

Render field
------------

[](#render-field)

You can use callback function when add field to render the field.

```
$config->addText(
	'general_section',
	array(
		'id'    => 'text_field_id',
		'label' => __( 'Hello World', 'plugin-name' ),
	),
	function( $args ) {
		$html  = sprintf(
			'',
			$args['type'],
			$args['name'],
			$args['value'],
			'Placeholder from callback'
		);
		$html .= 'This field is generated with callback parameter';
		echo $html;
		unset( $html );
	}
);
```

Add links in plugins list
-------------------------

[](#add-links-in-plugins-list)

You can add links below the plugin name in list.

[![](https://camo.githubusercontent.com/c86d41d1e637a364120248fd4b86c1dbf63d5d9c4c2e2202906fecedcc184cc2/68747470733a2f2f6f6265726f6e6c61692e626c6f672f77702d636f6e74656e742f75706c6f6164732f776f726470726573732d616e642d636f6d706f7365722f776f726470726573732d616e642d636f6d706f7365722d30392e6a7067)](https://camo.githubusercontent.com/c86d41d1e637a364120248fd4b86c1dbf63d5d9c4c2e2202906fecedcc184cc2/68747470733a2f2f6f6265726f6e6c61692e626c6f672f77702d636f6e74656e742f75706c6f6164732f776f726470726573732d616e642d636f6d706f7365722f776f726470726573732d616e642d636f6d706f7365722d30392e6a7067)

```
$config->addLink(
	'my-plugin',  // Your plugin's folder and main file name.
	array(
		array(
			'type' => 'default',
			'text' => __( 'Configure', 'plugin-name' ),
		),
		array(
			'type' => 'internal',
			'text' => __( 'Gravity Forms', 'plugin-name' ),
			'url'  => 'admin.php?page=gf_edit_forms',
		),
		array(
			'type' => 'external',
			'text' => __( 'Github Repo', 'plugin-name' ),
			'url'  => 'https://github.com/boospot/boo-settings-helper',
		),
	)
);
```

### Retrive field's value

[](#retrive-fields-value)

You can use WordPress get\_option() to get value. Don't forget the prefix name of field id. For example::

```
use ODS\Option;

$config = new Option( 'hello-world-' );
$config->addMenu();
$config->addTab();
$config->addText(
	'general_section',
	array(
		'id'                => 'my_text_field',
		'label'             => __( 'Hello World', 'plugin-name' ),
		'desc'              => __( 'Some description of my field', 'plugin-name' ),
		'placeholder'       => 'This is Placeholder',
		'show_in_rest'      => true,
		'class'             => 'my_custom_css_class',
		'size'              => 'regular',
	),
);
```

If you want to retrive field value of 'my\_text\_field', use code below:

```
$my_text_field_value = get_option( 'hello-world-my_text_field' );
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~30 days

Recently: every ~37 days

Total

6

Last Release

1631d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1587136?v=4)[Oberon Lai](/maintainers/oberonlai)[@oberonlai](https://github.com/oberonlai)

---

Top Contributors

[![oberonlai](https://avatars.githubusercontent.com/u/1587136?v=4)](https://github.com/oberonlai "oberonlai (6 commits)")

### Embed Badge

![Health badge](/badges/oberonlai-wp-option/health.svg)

```
[![Health](https://phpackages.com/badges/oberonlai-wp-option/health.svg)](https://phpackages.com/packages/oberonlai-wp-option)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
