function wdwt_get_option_defaults()
{
    $option_parameters = wdwt_get_option_parameters();
    $option_defaults = array();
    $current_theme = wp_get_theme();
    $option_defaults['theme_version'] = $current_theme->get('Version');
    foreach ($option_parameters as $option_parameter) {
        $name = isset($option_parameter['name']) && $option_parameter['name'] != '' ? $option_parameter['name'] : false;
        if ($name && isset($option_parameter['default'])) {
            $option_defaults[$name] = $option_parameter['default'];
        }
    }
    return apply_filters('WDWT_get_option_defaults', $option_defaults);
}
function wdwt_get_settings_by_tab()
{
    $tabs = wdwt_get_tabs();
    $settingsbytab = array();
    foreach ($tabs as $tab) {
        $tabname = $tab['name'];
        $settingsbytab[] = $tabname;
    }
    $option_parameters = wdwt_get_option_parameters();
    foreach ($option_parameters as $option_parameter) {
        $optionname = isset($option_parameter['name']) && $option_parameter['name'] != '' ? $option_parameter['name'] : false;
        if ($optionname) {
            $optiontab = $option_parameter['tab'];
            $settingsbytab[$optiontab][] = $optionname;
            $settingsbytab['all'][] = $optionname;
        }
    }
    return $settingsbytab;
}
Example #3
0
function wdwt_customizer_add_panels($wp_customize)
{
    /*
    the following sections are standard
    
    title_tagline – Site Title & Tagline
    colors – Colors
    header_image – Header Image
    background_image – Background Image
    nav – Navigation
    static_front_page – Static Front Page
    */
    $panels = wdwt_get_tabs();
    $priority = 1;
    // Add panels
    foreach ($panels as $panel => $panel_data) {
        $wp_customize->add_panel(WDWT_VAR . '_' . $panel, array('priority' => $priority, 'capability' => 'edit_theme_options', 'title' => $panel_data['title'], 'description' => $panel_data['description']));
        foreach ($panel_data['sections'] as $section => $section_data) {
            $wp_customize->add_section($section, array('priority' => $priority, 'capability' => 'edit_theme_options', 'title' => $section_data['title'], 'description' => $section_data['description'], 'panel' => WDWT_VAR . '_' . $panel));
        }
        $priority += 1;
    }
    /*move standard WP sections to general panel*/
    $general_links_priority = $wp_customize->get_section('general_links')->priority;
    $core_sections = array('title_tagline', 'header_image', 'background_image', 'static_front_page');
    $core_sections_priority = $general_links_priority + 1;
    foreach ($core_sections as $core_section) {
        $core_sect = $wp_customize->get_section($core_section);
        $core_sect->panel = WDWT_VAR . '_general';
        $core_sect->priority = $core_sections_priority;
        $core_sections_priority += 1;
    }
    /*move background color to color control panel*/
    $wp_customize->get_control('background_color')->section = 'color_control';
    $builtin_mods = array('background', 'navigation', 'site-title-tagline', 'static-front-page');
    $options = wdwt_get_option_parameters();
    // Add options to the section
    wdwt_customizer_add_section_options($options);
}
Example #4
0
function wdwt_options_validate($input)
{
    global $wdwt_options;
    $valid_input = $wdwt_options;
    $settingsbytab = wdwt_get_settings_by_tab();
    $option_parameters = wdwt_get_option_parameters();
    $option_defaults = wdwt_get_option_defaults();
    $tabs = wdwt_get_tabs();
    $submittype = 'submit';
    foreach ($tabs as $tab) {
        $resetname = 'reset-' . $tab['name'];
        if (!empty($input[$resetname])) {
            $submittype = 'reset';
        }
    }
    foreach ($tabs as $tab) {
        $submitname = 'submit-' . $tab['name'];
        $resetname = 'reset-' . $tab['name'];
        if (!empty($input[$submitname]) || !empty($input[$resetname])) {
            $submittab = $tab['name'];
        }
    }
    $tabsettings = isset($submittab) ? $settingsbytab[$submittab] : $settingsbytab['all'];
    foreach ($tabsettings as $setting) {
        if ('submit' == $submittype) {
            $optiondetails = $option_parameters[$setting];
            $valid_options = isset($optiondetails['valid_options']) ? $optiondetails['valid_options'] : false;
            $sanitize_type = isset($optiondetails['sanitize_type']) ? $optiondetails['sanitize_type'] : '';
            /* validate according to option type */
            switch ($optiondetails['type']) {
                case 'color':
                    $valid_input[$setting] = wdwt_param_clean($input[$setting], $valid_input[$setting], 'color', $sanitize_type);
                    break;
                case 'colors':
                    /*to refresh colors of active theme in themes options*/
                    $select_theme = $input[$setting]['select_theme'];
                    $theme_index = isset($input[$setting]['active']) ? intval($input[$setting]['active']) : 0;
                    /*corresponding themes options*/
                    /*add to input params*/
                    $valid_input[$select_theme] = $valid_input[$select_theme];
                    $valid_input[$select_theme]['active'] = $theme_index;
                    /* save color values from color panel to option*/
                    foreach ($input[$setting]['colors'] as $color => $color_array) {
                        $input[$setting]['colors'][$color]['value'] = wdwt_param_clean($color_array['value'], $valid_input[$setting]['colors'][$color]['value'], 'color');
                        /*also copy each color value to corresponding value in theme options array*/
                        $valid_input[$select_theme]['colors'][$theme_index][$color]['value'] = $input[$setting]['colors'][$color]['value'];
                        $valid_input[$select_theme]['colors'][$theme_index][$color]['default'] = $option_defaults[$select_theme]['colors'][$theme_index][$color]['default'];
                        $input[$setting]['colors'][$color]['default'] = $option_defaults[$select_theme]['colors'][$theme_index][$color]['default'];
                    }
                    $valid_input[$setting] = $input[$setting];
                    break;
                case 'checkbox':
                case 'checkbox_open':
                    $valid_input[$setting] = isset($input[$setting]) && $input[$setting] !== 'false' && $input[$setting] !== false ? true : false;
                    break;
                case 'radio':
                case 'radio_open':
                    $valid_input[$setting] = array_key_exists($input[$setting], $valid_options) ? $input[$setting] : $valid_input[$setting];
                    break;
                case 'layout':
                case 'layout_open':
                    $valid_input[$setting] = $input[$setting];
                    break;
                case 'select':
                case 'select_open':
                case 'select_style':
                    $valid_input[$setting] = wdwt_param_clean($input[$setting], array(), 'select', $sanitize_type, '', $valid_options);
                    break;
                case 'select_theme':
                    /* do nothing, the theme options are saved via color panel input (see case 'colors' in this switch)*/
                    break;
                case 'text':
                case 'textarea':
                case 'upload_single':
                    $valid_input[$setting] = wdwt_param_clean($input[$setting], '', 'text', $sanitize_type);
                    break;
                case 'textarea_slider':
                case 'text_slider':
                case 'upload_multiple':
                    $valid_input[$setting] = wdwt_param_clean($input[$setting], '', 'text_slider', $sanitize_type);
                    break;
                case 'text_diagram':
                    $valid_input[$setting] = wdwt_param_clean($input[$setting], '', 'text_diagram', $sanitize_type);
                    break;
                default:
                    /*do nothing*/
            }
        } elseif ('reset' == $submittype) {
            $valid_input[$setting] = $option_defaults[$setting];
        }
        /*set background color*/
        if (isset($optiondetails['mod']) && $optiondetails['mod']) {
            if ($setting == 'background_color') {
                set_theme_mod($setting, str_replace('#', '', $valid_input[$setting]));
            } else {
                set_theme_mod($setting, $valid_input[$setting]);
            }
        }
    }
    return $valid_input;
}