コード例 #1
0
/**
 * 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();
}
コード例 #2
0
/**
 * Retrieve settings tabs
 *
 * @since	1.0
 * @return	arr		$tabs
 */
function kbs_get_settings_tabs()
{
    $settings = kbs_get_registered_settings();
    $tabs = array();
    $tabs['general'] = __('General', 'kb-support');
    $tabs['tickets'] = sprintf(__('%s', 'kb-support'), kbs_get_ticket_label_plural());
    $tabs['kb_articles'] = sprintf(__('%s', 'kb-support'), kbs_get_kb_label_plural());
    $tabs['emails'] = __('Emails', 'kb-support');
    $tabs['styles'] = __('Styles', 'kb-support');
    if (!empty($settings['extensions'])) {
        $tabs['extensions'] = __('Extensions', 'kb-support');
    }
    if (!empty($settings['licenses'])) {
        $tabs['licenses'] = __('Licenses', 'kb-support');
    }
    $tabs['misc'] = __('Misc', 'kb-support');
    return apply_filters('kbs_settings_tabs', $tabs);
}
コード例 #3
0
ファイル: install.php プロジェクト: KB-Support/kb-support
/**
 * 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);
}