/**
 * Options Page
 *
 * Renders the options page contents.
 *
 * @since	0.1
 * @return	void
 */
function kbs_options_page()
{
    $settings_tabs = kbs_get_settings_tabs();
    $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
    $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? $_GET['tab'] : 'general';
    $sections = kbs_get_settings_tab_sections($active_tab);
    $key = 'main';
    if (is_array($sections)) {
        $key = key($sections);
    }
    $registered_sections = kbs_get_settings_tab_sections($active_tab);
    $section = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;
    // Unset 'main' if it's empty and default to the first non-empty if it's the chosen section
    $all_settings = kbs_get_registered_settings();
    // Let's verify we have a 'main' section to show
    ob_start();
    do_settings_sections('kbs_settings_' . $active_tab . '_main');
    $has_main_settings = strlen(ob_get_contents()) > 0;
    ob_end_clean();
    $override = false;
    if (false === $has_main_settings) {
        unset($sections['main']);
        if ('main' === $section) {
            foreach ($sections as $section_key => $section_title) {
                if (!empty($all_settings[$active_tab][$section_key])) {
                    $section = $section_key;
                    $override = true;
                    break;
                }
            }
        }
    }
    ob_start();
    ?>
	<div class="wrap">
		<h1 class="nav-tab-wrapper">
			<?php 
    foreach (kbs_get_settings_tabs() as $tab_id => $tab_name) {
        $tab_url = add_query_arg(array('settings-updated' => false, 'tab' => $tab_id));
        // Remove the section from the tabs so we always end up at the main section
        $tab_url = remove_query_arg('section', $tab_url);
        $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
        echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
        echo esc_html($tab_name);
        echo '</a>';
    }
    ?>
		</h1>
		<?php 
    $number_of_sections = count($sections);
    $number = 0;
    if ($number_of_sections > 1) {
        echo '<div><ul class="subsubsub">';
        foreach ($sections as $section_id => $section_name) {
            echo '<li>';
            $number++;
            $tab_url = add_query_arg(array('settings-updated' => false, 'tab' => $active_tab, 'section' => $section_id));
            $class = '';
            if ($section == $section_id) {
                $class = 'current';
            }
            echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
            if ($number != $number_of_sections) {
                echo ' | ';
            }
            echo '</li>';
        }
        echo '</ul></div>';
    }
    ?>
		<div id="tab_container">
			<form method="post" action="options.php">
				<table class="form-table">
				<?php 
    settings_fields('kbs_settings');
    if ('main' === $section) {
        do_action('kbs_settings_tab_top', $active_tab);
    }
    do_action('kbs_settings_tab_top_' . $active_tab . '_' . $section);
    do_settings_sections('kbs_settings_' . $active_tab . '_' . $section);
    do_action('kbssettings_tab_bottom_' . $active_tab . '_' . $section);
    // For backwards compatibility
    if ('main' === $section) {
        do_action('kbs_settings_tab_bottom', $active_tab);
    }
    // If the main section was empty and we overrode the view with the next subsection, prepare the section for saving
    if (true === $override) {
        ?>
<input type="hidden" name="kbs_section_override" value="<?php 
        echo $section;
        ?>
" /><?php 
    }
    ?>
				</table>
				<?php 
    submit_button();
    ?>
			</form>
		</div><!-- #tab_container-->
	</div><!-- .wrap -->
	<?php 
    echo ob_get_clean();
}
/**
 * Add all settings sections and fields.
 *
 * @since	1.0
 * @return	void
*/
function kbs_register_settings()
{
    if (false == get_option('kbs_settings')) {
        add_option('kbs_settings');
    }
    foreach (kbs_get_registered_settings() as $tab => $sections) {
        foreach ($sections as $section => $settings) {
            // Check for backwards compatibility
            $section_tabs = kbs_get_settings_tab_sections($tab);
            if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) {
                $section = 'main';
                $settings = $sections;
            }
            add_settings_section('kbs_settings_' . $tab . '_' . $section, __return_null(), '__return_false', 'kbs_settings_' . $tab . '_' . $section);
            foreach ($settings as $option) {
                // For backwards compatibility
                if (empty($option['id'])) {
                    continue;
                }
                $name = isset($option['name']) ? $option['name'] : '';
                add_settings_field('kbs_settings[' . $option['id'] . ']', $name, function_exists('kbs_' . $option['type'] . '_callback') ? 'kbs_' . $option['type'] . '_callback' : 'kbs_missing_callback', 'kbs_settings_' . $tab . '_' . $section, 'kbs_settings_' . $tab . '_' . $section, array('section' => $section, 'id' => isset($option['id']) ? $option['id'] : null, 'desc' => !empty($option['desc']) ? $option['desc'] : '', 'name' => isset($option['name']) ? $option['name'] : null, 'size' => isset($option['size']) ? $option['size'] : null, 'options' => isset($option['options']) ? $option['options'] : '', 'std' => isset($option['std']) ? $option['std'] : '', 'min' => isset($option['min']) ? $option['min'] : null, 'max' => isset($option['max']) ? $option['max'] : null, 'step' => isset($option['step']) ? $option['step'] : null, 'chosen' => isset($option['chosen']) ? $option['chosen'] : null, 'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null, 'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true, 'readonly' => isset($option['readonly']) ? $option['readonly'] : false, 'faux' => isset($option['faux']) ? $option['faux'] : false));
            }
        }
    }
    // Creates our settings in the options table
    register_setting('kbs_settings', 'kbs_settings', 'kbs_settings_sanitize');
}
Beispiel #3
0
/**
 * Run the KBS Install process
 *
 * @since	1.0
 * @return	void
 */
function kbs_run_install()
{
    global $wpdb, $kbs_options, $wp_version;
    // Setup the Custom Post Types
    kbs_setup_kbs_post_types();
    // Setup the Custom Taxonomies
    kbs_setup_custom_taxonomies();
    // Clear the permalinks
    flush_rewrite_rules(false);
    // Add Upgraded From Option
    $current_version = get_option('kbs_version');
    if ($current_version) {
        update_option('kbs_version_upgraded_from', $current_version);
    }
    // Setup some default options
    $options = array();
    // Pull options from WP, not KBS' global
    $current_options = get_option('kbs_settings', array());
    // Populate some default values
    foreach (kbs_get_registered_settings() as $tab => $sections) {
        foreach ($sections as $section => $settings) {
            // Check for backwards compatibility
            $tab_sections = kbs_get_settings_tab_sections($tab);
            if (!is_array($tab_sections) || !array_key_exists($section, $tab_sections)) {
                $section = 'main';
                $settings = $sections;
            }
            foreach ($settings as $option) {
                if (!empty($option['std'])) {
                    if ('checkbox' == $option['type']) {
                        $options[$option['id']] = '1';
                    } else {
                        $options[$option['id']] = $option['std'];
                    }
                }
            }
        }
    }
    $merged_options = array_merge($kbs_options, $options);
    $kbs_options = $merged_options;
    update_option('kbs_settings', $merged_options);
    update_option('kbs_version', KBS_VERSION);
    // Create KBS support roles
    $roles = new KBS_Roles();
    $roles->add_roles();
    $roles->add_caps();
    // Create the customer databases
    @KBS()->customers->create_table();
    @KBS()->customer_meta->create_table();
    // Add a temporary option to note that KBS pages have been created
    set_transient('_kbs_installed', $merged_options, 30);
    /*if ( ! $current_version ) {
    		require_once KBS_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php';
    
    		// When new upgrade routines are added, mark them as complete on fresh install
    		$upgrade_routines = array();
    
    		foreach ( $upgrade_routines as $upgrade ) {
    			kbs_set_upgrade_complete( $upgrade );
    		}
    	}*/
    // Bail if activating from network, or bulk
    if (is_network_admin() || isset($_GET['activate-multi'])) {
        return;
    }
    // Add the transient to redirect
    set_transient('_kbs_activation_redirect', true, 30);
}