コード例 #1
0
/**
 * Callback for add_settings_section()
 * 
 * Generic callback to output the section text
 * for each Plugin settings section. 
 * 
 * @uses	cleanyetibasic_get_settings_page_tabs()	Defined in /functions/options.php
 * 
 * @param	array	$section_passed	Array passed from add_settings_section()
 */
function cleanyetibasic_sections_callback($section_passed)
{
    global $cleanyetibasic_tabs;
    $cleanyetibasic_tabs = cleanyetibasic_get_settings_page_tabs();
    foreach ($cleanyetibasic_tabs as $tabname => $tab) {
        $tabsections = $tab['sections'];
        foreach ($tabsections as $sectionname => $section) {
            if ('cleanyetibasic_' . $sectionname . '_section' == $section_passed['id']) {
                ?>
				<p><?php 
                echo $section['description'];
                ?>
</p>
				<?php 
            }
        }
    }
}
コード例 #2
0
/**
 * Clean Yeti Basic Theme Settings Theme Customizer Implementation
 *
 * Implement the Theme Customizer for the 
 * Clean Yeti Basic Theme Settings.
 * 
 * @param 	object	$wp_customize	Object that holds the customizer data
 * 
 * @link	http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-own-themes/	Otto
 */
function cleanyetibasic_register_theme_customizer($wp_customize)
{
    // Failsafe is safe
    if (!isset($wp_customize)) {
        return;
    }
    global $cleanyetibasic_options;
    $cleanyetibasic_options = cleanyetibasic_get_options();
    // Get the array of option parameters
    $option_parameters = cleanyetibasic_get_option_parameters();
    // Get list of tabs
    $tabs = cleanyetibasic_get_settings_page_tabs();
    // Add Sections
    foreach ($tabs as $tab) {
        // Add $tab section
        $wp_customize->add_section('cleanyetibasic_' . $tab['name'], array('title' => $tab['title']));
    }
    // Add Settings
    foreach ($option_parameters as $option_parameter) {
        // sanitize callback based on type
        if ('text' == $option_parameter['type']) {
            $sanitize = 'cleanyetibasic_sanitize_text';
        } else {
            if ('checkbox' == $option_parameter['type']) {
                $sanitize = 'cleanyetibasic_sanitize_checkbox';
            } else {
                if ('radio' == $option_parameter['type'] || 'select' == $option_parameter['type']) {
                    $sanitize = 'cleanyetibasic_sanitize_choices';
                } else {
                    if ('color-picker' == $option_parameter['type']) {
                        $sanitize = 'sanitize_hex_color';
                    }
                }
            }
        }
        // Add $option_parameter setting
        $wp_customize->add_setting('theme_cleanyetibasic_options[' . $option_parameter['name'] . ']', array('default' => $option_parameter['default'], 'type' => 'option', 'sanitize_callback' => $sanitize));
        // Add $option_parameter control
        if ('text' == $option_parameter['type']) {
            $wp_customize->add_control('cleanyetibasic_' . $option_parameter['name'], array('label' => $option_parameter['title'], 'section' => 'cleanyetibasic_' . $option_parameter['tab'], 'settings' => 'theme_cleanyetibasic_options[' . $option_parameter['name'] . ']', 'type' => 'text'));
        } else {
            if ('checkbox' == $option_parameter['type']) {
                $wp_customize->add_control('cleanyetibasic_' . $option_parameter['name'], array('label' => $option_parameter['title'], 'section' => 'cleanyetibasic_' . $option_parameter['tab'], 'settings' => 'theme_cleanyetibasic_options[' . $option_parameter['name'] . ']', 'type' => 'checkbox'));
            } else {
                if ('radio' == $option_parameter['type']) {
                    $valid_options = array();
                    foreach ($option_parameter['valid_options'] as $valid_option) {
                        $valid_options[$valid_option['name']] = $valid_option['title'];
                    }
                    $wp_customize->add_control('cleanyetibasic_' . $option_parameter['name'], array('label' => $option_parameter['title'], 'section' => 'cleanyetibasic_' . $option_parameter['tab'], 'settings' => 'theme_cleanyetibasic_options[' . $option_parameter['name'] . ']', 'type' => 'radio', 'choices' => $valid_options));
                } else {
                    if ('select' == $option_parameter['type']) {
                        $valid_options = array();
                        foreach ($option_parameter['valid_options'] as $valid_option) {
                            $valid_options[$valid_option['name']] = $valid_option['title'];
                        }
                        $wp_customize->add_control('cleanyetibasic_' . $option_parameter['name'], array('label' => $option_parameter['title'], 'section' => 'cleanyetibasic_' . $option_parameter['tab'], 'settings' => 'theme_cleanyetibasic_options[' . $option_parameter['name'] . ']', 'type' => 'select', 'choices' => $valid_options));
                    } else {
                        if ('color-picker' == $option_parameter['type']) {
                            $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'cleanyetibasic_' . $option_parameter['name'], array('label' => $option_parameter['title'], 'section' => 'cleanyetibasic_' . $option_parameter['tab'], 'settings' => 'theme_cleanyetibasic_options[' . $option_parameter['name'] . ']')));
                        } else {
                            if ('custom' == $option_parameter['type']) {
                                $valid_options = array();
                                foreach ($option_parameter['valid_options'] as $valid_option) {
                                    $valid_options[$valid_option['name']] = $valid_option['title'];
                                }
                                $wp_customize->add_control('cleanyetibasic_' . $option_parameter['name'], array('label' => $option_parameter['title'], 'section' => 'cleanyetibasic_' . $option_parameter['tab'], 'settings' => 'theme_cleanyetibasic_options[' . $option_parameter['name'] . ']', 'type' => 'select', 'choices' => $valid_options));
                            }
                        }
                    }
                }
            }
        }
    }
}
コード例 #3
0
ファイル: options.php プロジェクト: shoaibik/clean-yeti-basic
/**
 * Separate settings by tab
 * 
 * Returns an array of tabs, each of
 * which is an indexed array of settings
 * included with the specified tab.
 *
 * @uses	cleanyetibasic_get_option_parameters()	defined in \functions\options.php
 * @uses	cleanyetibasic_get_settings_page_tabs()	defined in \functions\options.php
 * 
 * @return	array	$settingsbytab	array of arrays of settings by tab
 */
function cleanyetibasic_get_settings_by_tab()
{
    // Get the list of settings page tabs
    $tabs = cleanyetibasic_get_settings_page_tabs();
    // Initialize an array to hold
    // an indexed array of tabnames
    $settingsbytab = array();
    // Loop through the array of tabs
    foreach ($tabs as $tab) {
        $tabname = $tab['name'];
        // Add an indexed array key
        // to the settings-by-tab
        // array for each tab name
        $settingsbytab[] = $tabname;
    }
    // Get the array of option parameters
    $option_parameters = cleanyetibasic_get_option_parameters();
    // Loop through the option parameters
    // array
    foreach ($option_parameters as $option_parameter) {
        $optiontab = $option_parameter['tab'];
        $optionname = $option_parameter['name'];
        // Add an indexed array key to the
        // settings-by-tab array for each
        // setting associated with each tab
        $settingsbytab[$optiontab][] = $optionname;
        $settingsbytab['all'][] = $optionname;
    }
    // Return the settings-by-tab
    // array
    return $settingsbytab;
}