Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Modular theme options
function ap_core_do_theme_options() {
ap_core_tab_setup();
ap_core_general_settings();
ap_core_typography_settings();
ap_core_advanced_settings();
}
function ap_core_general_settings() {
$options_before = '<table class="form-table" id="tabs-1">';
$options_after = '</table>';
echo $options_before;
ap_core_sidebar_option();
ap_core_posts_excerpts_option();
ap_core_footer_option();
ap_core_presstrends_option();
echo $options_after;
}
function ap_core_sidebar_option() {
$defaults = ap_core_get_theme_defaults();
$options = get_option( 'ap_core_theme_options', $defaults );
ob_start();
?>
<tr valign="top"><th scope="row"><?php _e( 'Sidebar', 'museum-core' ); ?></th>
<td>
<select name="ap_core_theme_options[sidebar]">
<?php
$selected = $options['sidebar'];
foreach ( ap_core_sidebar() as $option ) {
$label = $option['label'];
$value = $option['value'];
echo '<option value="' . $value . '" ' . selected( $selected, $value ) . '>' . $label . '</option>';
}
?>
</select>
</td>
</tr>
<?php
$sidebar = ob_get_contents();
ob_end_clean();
echo $sidebar;
}
<form method="post" action="options.php">
<div id="tabs">
<?php settings_fields( 'AP_CORE_OPTIONS' ); ?>
<?php ap_core_do_theme_options(); ?>
</div>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e( 'Save Options', 'museum-core' ); ?>" />
<input type="hidden" name="ap-core-settings-submit" value="Y" />
</p>
</form>
function do_my_custom_theme_options() {
my_custom_tab_setup();
ap_core_general_settings();
ap_core_typography_settings();
ap_core_advanced_settings();
my_custom_theme_settings();
}
function my_custom_tab_setup() {
ob_start();
?>
<div class="tab-wrap">
<ul class="nav-tab-wrapper">
<li><?php screen_icon(); ?></li>
<li><h2><a class="nav-tab" href="#tabs-1"><?php _e('General','museum-core'); ?></a></h2></li>
<li><h2><a class="nav-tab" href="#tabs-2"><?php _e('Font Stuff','my-theme'); ?></a></h2></li>
<li><h2><a class="nav-tab" href="#tabs-3"><?php _e('Advanced','museum-core'); ?></a></h2></li>
<li><h2><a class="nav-tab" href="#tabs-4"><?php _e('Custom Tab','my-theme'); ?></a></h2></li>
</ul>
</div>
<?php
$tabs = ob_get_contents();
ob_end_clean();
echo $tabs;
}
function my_custom_theme_settings() {
$options = get_option( 'my_custom_theme_options' );
ob_start();
?>
<table class="form-table" id="tabs-4">
<tr valign="top"><th scope="row"><?php _e( 'Hello World!', 'museum-core' ); ?></th>
<td>
<select name="ap_core_theme_options[hello]">
<?php
$selected = $options['hello'];
foreach ( ap_core_true_false() as $option ) {
$label = $option['label'];
$value = $option['value'];
echo '<option value="' . $value . '" ' . selected( $selected, $value ) . '>' . $label . '</option>';
} ?>
</select><br />
<label class="description" for="my_custom_theme_options[hello]"><?php _e( 'Some description of my setting.', 'museum-core' ); ?></label>
</td>
</tr>
</table>
<?php
$custom = ob_get_contents();
ob_end_clean();
echo $custom;
}
<?php
if (!function_exists('ap_core_do_theme_options')) {
function ap_core_do_theme_options() {
do_my_custom_theme_options();
}
}
function do_my_custom_theme_options() {
my_custom_tab_setup();
ap_core_general_settings();
ap_core_typography_settings();
ap_core_advanced_settings();
my_custom_theme_settings();
}
function my_custom_tab_setup() {
ob_start();
?>
<div class="tab-wrap">
<ul class="nav-tab-wrapper">
<li><?php screen_icon(); ?></li>
<li><h2><a class="nav-tab" href="#tabs-1"><?php _e('General','museum-core'); ?></a></h2></li>
<li><h2><a class="nav-tab" href="#tabs-2"><?php _e('Font Stuff','my-theme'); ?></a></h2></li>
<li><h2><a class="nav-tab" href="#tabs-3"><?php _e('Advanced','museum-core'); ?></a></h2></li>
<li><h2><a class="nav-tab" href="#tabs-4"><?php _e('Custom Tab','my-theme'); ?></a></h2></li>
</ul>
</div>
<?php
$tabs = ob_get_contents();
ob_end_clean();
echo $tabs;
}
function my_custom_theme_settings() {
$options = get_option( 'my_custom_theme_options' );
ob_start();
?>
<table class="form-table" id="tabs-4">
<tr valign="top"><th scope="row"><?php _e( 'Hello World!', 'museum-core' ); ?></th>
<td>
<select name="ap_core_theme_options[hello]">
<?php
$selected = $options['hello'];
foreach ( ap_core_true_false() as $option ) {
$label = $option['label'];
$value = $option['value'];
echo '<option value="' . $value . '" ' . selected( $selected, $value ) . '>' . $label . '</option>';
} ?>
</select><br />
<label class="description" for="my_custom_theme_options[hello]"><?php _e( 'Some description of my setting.', 'museum-core' ); ?></label>
</td>
</tr>
</table>
<?php
$custom = ob_get_contents();
ob_end_clean();
echo $custom;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.