PHP code example of webkinder / wordpress-options-page-api

1. Go to this page and download the library: Download webkinder/wordpress-options-page-api 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/ */

    

webkinder / wordpress-options-page-api example snippets


use WebKinder\SettingsAPI;

(new SettingsAPI(['network_settings' => false]))
	->set_sections(
		[
			[
				'id' => 'custom_options',
				'title' => __('Custom Options'),
			],
		]
	)
	->set_fields([
		'custom_options' => [
			[
				'name' => 'information_text',
				'label' => __('Information Text'),
				'type' => 'textarea',
			],
			[
				'name' => 'radio_option',
				'label' => __('Radio Option'),
				'type' => 'radio',
				'options' => [
					'top' => __('Top'),
					'bottom' => __('Bottom'),
					'bottom-right' => __('Bottom Right'),
				],
			],
			[
				'name' => 'checkbox_option',
				'label' => __('Checkbox Option'),
				'type' => 'checkbox',
				'desc' => __('aktivieren'),
			],
			[
				'name' => 'multicheck_option',
				'label' => __('Multicheck Options'),
				'type' => 'multicheck',
				'options' => [
					'top' => __('Top'),
					'bottom' => __('Bottom'),
					'bottom-right' => __('Bottom Right'),
				],
			],
		],
	])
	->register_page('Options page', 'Options page', 'manage_options', 'custom-options-page')
	->admin_init()
;


/**
 * Get the value of a settings field
 *
 * @param string $option settings field name
 * @param string $section the section name this field belongs to
 * @param string $default default text if it's not found
 *
 * @return mixed
 */
function prefix_get_option( $option, $section, $default = '' ) {

    $options = get_option( $section );

    if ( isset( $options[$option] ) ) {
        return $options[$option];
    }

    return $default;
}