PHP code example of diazoxide / wp-lib-option

1. Go to this page and download the library: Download diazoxide/wp-lib-option library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

diazoxide / wp-lib-option example snippets


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

$config = [
    'name'=>'Arthur',
    'country' => new Option(
        [
            'default'     => 'uk',
            'type'        => Option::TYPE_TEXT,
            'method'      => Option::METHOD_SINGLE,
            'values'      => [
                'fr'=>"France",
                'uk'=>"United Kingdom",
                'it'=>"Italy"
            ],
            'label'       => 'Country',
            'description' => 'Select country.'
        ]
    ),
    'other'=>[
        'is_solder'=>new Option(
             [
                 'default'     => false,
                 'type'        => Option::TYPE_BOOL,
                 'label'       => 'Solder or not'
             ]
         )
    ]
];

Option::printForm(
    'custom_index_key_for_config',
    $config,
    [
        'title' => 'Arthur Configuration'
    ]
);

$options = Option::expandOptions(
    $config,
    'custom_index_key_for_config'
);

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`