PHP code example of yivi / wp_optional

1. Go to this page and download the library: Download yivi/wp_optional 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/ */

    

yivi / wp_optional example snippets



$page_settings = new PageSettings(
                 'options_id',
                 'Options Page Title',
                 'Options Menu Title',
                 'options-general.php', // options menu parent
                 'manage_options'       // capability 

$page_general = $page_settings->addSubpage(
    'general',
    __( 'General', TEXT_DOMAIN ),
    'manage_options'
 );

$general_main = $page_general->addSection( 'main', __( 'Automatic Generation', TEXT_DOMAIN ) );

 $field = $page_general->addField(
     // string identifying the field (will be concatenated to the section, page and options id)
     $id,
     // will be used as a label for the <input> element
     $title,
     // this should be a class that extends AbstractField,
     $type
 );

 


$page_general->addField($id, $title, SelectField::class)
             ->setClass('optional')
             ->setAttributes($attribute_array)
             ->setChoices($choices_array);