WordPress Option

1.0.2 2020-09-04 08:46 UTC

This package is auto-updated.

Last update: 2024-02-10 19:47:09 UTC


Create dynamic admin settings page with flexible configurations.


  • Single
  • Multiple


  • Boolean
  • Text
  • Object
  • Group


  • Text
  • Checkbox
  • Select
  • Number
  • Textarea


How to install

Install with composer

On your custom plugin directory run this composer command

composer require diazoxide/wp-lib-option:dev-master

Or add in your composer.json require field

 "require": {
    "diazoxide/wp-lib-option": "dev-master"

How to use

For example we have multidimensional array $config that have one static value name, two dynamic values country and other->is_solder.

country field should be set by user from admin side

use diazoxide\wp\lib\option\v2\Option;

$config = [
    'country' => new Option(
            'default'     => 'uk',
            'type'        => Option::TYPE_TEXT,
            'method'      => Option::METHOD_SINGLE,
            'values'      => [
                'uk'=>"United Kingdom",
            'label'       => 'Country',
            'description' => 'Select country.'
        'is_solder'=>new Option(
                 'default'     => false,
                 'type'        => Option::TYPE_BOOL,
                 'label'       => 'Solder or not'

Print this config form

        'title' => 'Arthur Configuration'

If change values from printed form and click save, then all changes will be stored on wp_options table with custom custom_index_key_for_config prefix.

Getting final values of this options

$options = Option::expandOptions(

So we have already expanded options with dynamic and static values. You can use it simply.

For example

echo $options['name']; // Output: Arthur

echo $options['country']; // Output is dynamic. Default value is `fr`

var_dump($options['other']['is_solder']); // Output is dynamic. Default value is `false`