Skip to content

Creating Option Pages

Darko Gjorgjijoski edited this page Mar 3, 2021 · 2 revisions

Option pages can be easily created using the IgniteKit\WP\OptionBuilder\Framework class. The library supports multiple option pages as well.

The class instance needs to be before all other hooks. Meaning that you shouldn't instance it and register the options in init, plugins_loaded or other actions.

use IgniteKit\WP\OptionBuilder\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 = new Framework();
$framework->register_settings( array( $settings ) );
Clone this wiki locally