Last active
September 10, 2017 04:21
-
-
Save themeblvd/ea7f319d7963553970b9711e7b75370d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( class_exists( 'Theme_Blvd_Options_Page' ) ) { | |
class My_Options_Page extends Theme_Blvd_Options_Page { | |
/** | |
* This method needs to be overwritten because | |
* the parent class uses add_theme_page() which | |
* can only add pages as subpages to the | |
* Appearance menu. | |
*/ | |
public function add_page() { | |
/* @link https://codex.wordpress.org/Administration_Menus */ | |
$admin_page = add_menu_page( | |
$this->args['page_title'], | |
$this->args['menu_title'], | |
$this->args['cap'], | |
$this->args['menu_slug'], | |
array( $this, 'admin_page' ) | |
); | |
add_action( | |
'admin_print_styles-' . $admin_page, | |
array( $this, 'load_styles' ) | |
); | |
add_action( | |
'admin_print_scripts-' . $admin_page, | |
array( $this, 'load_scripts' ) | |
); | |
} | |
} | |
} | |
function my_setup_options_page() { | |
if ( ! class_exists( 'My_Options_Page' ) ) { | |
return; | |
} | |
$options = array( | |
array( | |
'name' => 'Tab #1', | |
'type' => 'heading', | |
), | |
array( | |
'name' => 'Section A', | |
'type' => 'section_start', | |
), | |
array( | |
'name' => 'Option #1', | |
'desc' => 'This is the description for the first option.', | |
'id' => 'my_option_1', | |
'std' => 'default value for option #1', | |
'type' => 'text', | |
), | |
array( | |
'name' => 'Option #2', | |
'desc' => 'This is the description for the second option.', | |
'id' => 'my_option_2', | |
'std' => 'default value for option #2', | |
'type' => 'textarea', | |
), | |
array( | |
'name' => 'Option #3', | |
'desc' => 'This is the description for the third option.', | |
'id' => 'my_option_3', | |
'std' => 'default value for option #3', | |
'type' => 'select', | |
'options' => array( | |
'thing_1' => 'Thing 1', | |
'thing_2' => 'Thing 2', | |
'thing_3' => 'Thing 3', | |
'thing_4' => 'Thing 4', | |
), | |
), | |
array( | |
'type' => 'section_end', | |
), | |
array( | |
'name' => 'Section B', | |
'type' => 'section_start', | |
), | |
array( | |
'name' => 'Option #4', | |
'desc' => 'This is the description for the fourth option.', | |
'id' => 'my_option_4', | |
'std' => 'default value for option #4', | |
'type' => 'text', | |
), | |
array( | |
'type' => 'section_end', | |
), | |
array( | |
'name' => 'Tab #2', | |
'type' => 'heading', | |
), | |
array( | |
'name' => 'Section C', | |
'type' => 'section_start', | |
), | |
array( | |
'name' => 'Option #5', | |
'desc' => 'This is the description for the fourth option.', | |
'id' => 'my_option_5', | |
'std' => 'default value for option #5', | |
'type' => 'text', | |
), | |
array( | |
'type' => 'section_end', | |
), | |
array( | |
'name' => 'Section D', | |
'type' => 'section_start', | |
), | |
array( | |
'name' => 'Option #6', | |
'desc' => 'This is the description for the fourth option.', | |
'id' => 'my_option_6', | |
'std' => 'default value for option #6', | |
'type' => 'text', | |
), | |
array( | |
'type' => 'section_end', | |
), | |
); | |
$args = array( | |
'page_title' => 'My Options', | |
'menu_title' => 'My Options', | |
); | |
$page = new My_Options_Page( 'my-options', $options, $args ); | |
// On frontend, you'll retrieve saved settings like this: | |
// $settings = get_option( 'my-options' ); | |
} | |
add_action( 'after_setup_theme', 'my_setup_options_page' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment