PHP code example of ignitekit / wp-option-builder

1. Go to this page and download the library: Download ignitekit/wp-option-builder 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/ */

    

ignitekit / wp-option-builder example snippets




use IgniteKit\WP\OptionBuilder\Framework;
$framework = new Framework();


$settings = array(
	'id'    => 'custom_options',
	'pages' => array(
		array(
			'id'              => 'test_page',
			'parent_slug'     => 'themes.php',
			'page_title'      => __( 'Theme Options', 'your-text-domain' ),
			'menu_title'      => __( 'Theme Options', 'your-text-domain' ),
			'capability'      => 'edit_theme_options',
			'menu_slug'       => 'demo-theme-options',
			'icon_url'        => null,
			'position'        => null,
			'updated_message' => __( 'Options updated!', 'your-text-domain' ),
			'reset_message'   => __( 'Options reset!', 'your-text-domain' ),
			'button_text'     => __( 'Save changes', 'your-text-domain' ),
			'show_buttons'    => true,
			'screen_icon'     => 'options-general',
			'contextual_help' => array(
				'content' => array( array(
						'id'      => 'option_types_help',
						'title'   => __( 'Option Types', 'theme-text-domain' ),
						'content' => '<p>' . __( 'Help content goes here!', 'theme-text-domain' ) . '</p>',
					),
				),
				'sidebar' => '<p>' . __( 'Sidebar content goes here!', 'theme-text-domain' ) . '</p>',
			),
			'sections' => array( array(
				'id'    => 'option_types',
				'title' => __( 'Option Types', 'theme-text-domain' ),
			    ),
			),
			'settings'        => array(
				array(
					'id'           => 'demo_background',
					'label'        => __( 'Background', 'theme-text-domain' ),
					'desc'         => __( 'Some description goes here...', 'theme-text-domain' ),
					'std'          => '',
					'type'         => 'background',
					'section'      => 'option_types',
					'rows'         => '',
					'post_type'    => '',
					'taxonomy'     => '',
					'min_max_step' => '',
					'class'        => '',
					'condition'    => '',
					'operator'     => 'and',
				),
				array(
					'id'           => 'demo_border',
					'label'        => __( 'Border', 'theme-text-domain' ),
					'desc'         => __( 'Some description goes here...', 'theme-text-domain' ),
					'std'          => '',
					'type'         => 'border',
					'section'      => 'option_types',
					'rows'         => '',
					'post_type'    => '',
					'taxonomy'     => '',
					'min_max_step' => '',
					'class'        => '',
					'condition'    => '',
					'operator'     => 'and',
				),
				array(
					'id'           => 'demo_box_shadow',
					'label'        => __( 'Box Shadow', 'theme-text-domain' ),
					'desc'         => __( 'Some description goes here...', 'theme-text-domain' ),
					'std'          => '',
					'type'         => 'box-shadow',
					'section'      => 'option_types',
					'rows'         => '',
					'post_type'    => '',
					'taxonomy'     => '',
					'min_max_step' => '',
					'class'        => '',
					'condition'    => '',
					'operator'     => 'and',
				),
			)
		)
	)
);

$framework->register_settings( array( $settings ) ); // Note: $settings one group option pages, you can add multiple groups of pages.

// Make settings instance
$settings = get_option('custom_options');

// To access demo_background setting
$demo_bg = isset($settings['demo_background']) ? $settings['demo_background'] : ''; // or simply $settings['demo_background'].


$framework->register_metabox( array(
	'id'       => 'demo_meta_box',
	'title'    => __( 'Demo Meta Box', 'theme-text-domain' ),
	'desc'     => '',
	'pages'    => array( 'post' ),
	'context'  => 'normal',
	'priority' => 'high',
	'fields'   => array(
		array(
			'label' => __( 'Conditions', 'theme-text-domain' ),
			'id'    => 'demo_conditions',
			'type'  => 'tab',
		),
		array(
			'label' => __( 'Show Gallery', 'theme-text-domain' ),
			'id'    => 'demo_show_gallery',
			'type'  => 'on-off',
			'desc'  => sprintf( __( 'Shows the Gallery when set to %s.', 'theme-text-domain' ), '<code>on</code>' ),
			'std'   => 'off',
		),
		array(
			'label'     => '',
			'id'        => 'demo_textblock',
			'type'      => 'textblock',
			'desc'      => __( 'Congratulations, you created a gallery!', 'theme-text-domain' ),
			'operator'  => 'and',
			'condition' => 'demo_show_gallery:is(on),demo_gallery:not()',
		),
		array(
			'label'     => __( 'Gallery', 'theme-text-domain' ),
			'id'        => 'demo_gallery',
			'type'      => 'gallery',
			'desc'      => sprintf( __( 'This is a Gallery option type. It displays when %s.', 'theme-text-domain' ), '<code>demo_show_gallery:is(on)</code>' ),
			'condition' => 'demo_show_gallery:is(on)',
		),
		array(
			'label' => __( 'More Options', 'theme-text-domain' ),
			'id'    => 'demo_more_options',
			'type'  => 'tab',
		),
		array(
			'label' => __( 'Text', 'theme-text-domain' ),
			'id'    => 'demo_text',
			'type'  => 'text',
			'desc'  => __( 'This is a demo Text field.', 'theme-text-domain' ),
		),
		array(
			'label' => __( 'Textarea', 'theme-text-domain' ),
			'id'    => 'demo_textarea',
			'type'  => 'textarea',
			'desc'  => __( 'This is a demo Textarea field.', 'theme-text-domain' ),
		),
	),
) );

$value = get_post_meta($post_id, 'demo_text', true);

$data = get_post_meta($post_id, 'demo_meta_box', true);
$value = $data['demo_text'];