Beispiel #1
0
/**
 * Sanitize font style
 * @param string
 * @param string
 */
function et_sanitize_font_style($styles)
{
    // List of allowable style
    $allowed_styles = array_keys(et_extra_font_style_choices());
    // Explodes styles into array
    $styles_array = explode('|', $styles);
    // Get valid styles
    $valid_styles = array_intersect($allowed_styles, $styles_array);
    // Return sanitized styles
    return implode("|", $valid_styles);
}
Beispiel #2
0
function et_register_customizer_section($wp_customize, $settings, $section, $section_options = '', $panel = '')
{
    global $shortname;
    if (empty($settings)) {
        return;
    }
    $section_args = wp_parse_args($section_options, array('title' => $section, 'priority' => 10));
    if (!empty($panel)) {
        $section_args['panel'] = $panel;
    }
    $wp_customize->add_section($section, $section_args);
    foreach ($settings as $option_key => $options) {
        if (!is_array($options)) {
            $label = $options;
            $options = array();
            $options['label'] = $label;
        }
        $default_options = array('setting_type' => 'option', 'type' => 'text', 'transport' => 'postMessage', 'capability' => 'edit_theme_options', 'default' => '', 'description' => '', 'choices' => array(), 'priority' => 10, 'global_option' => false, 'theme_supports' => '');
        $options = wp_parse_args($options, $default_options);
        $option_key = true == $options['global_option'] ? $option_key : sprintf('et_%s[%s]', $shortname, $option_key);
        switch ($options['type']) {
            case 'dropdown-font-styles':
                $sanitize_callback = 'et_sanitize_font_style';
                break;
            case 'dropdown-fonts':
                $sanitize_callback = 'et_sanitize_font_choices';
                break;
            case 'color':
                $sanitize_callback = 'sanitize_hex_color';
                break;
            case 'et_coloralpha':
                $sanitize_callback = 'et_sanitize_alpha_color';
                break;
            case 'checkbox':
                $sanitize_callback = 'wp_validate_boolean';
                break;
            case 'range':
                if (isset($options['input_attrs']['step']) && $options['input_attrs']['step'] < 1) {
                    $sanitize_callback = 'et_sanitize_float_number';
                } else {
                    $sanitize_callback = 'et_sanitize_int_number';
                }
                break;
            default:
                $sanitize_callback = '';
                break;
        }
        $wp_customize->add_setting($option_key, array('default' => $options['default'], 'type' => $options['setting_type'], 'capability' => $options['capability'], 'transport' => $options['transport'], 'theme_supports' => $options['theme_supports'], 'sanitize_callback' => $sanitize_callback));
        $control_options = array('label' => $options['label'], 'section' => $section, 'description' => $options['description'], 'settings' => $option_key, 'type' => $options['type'], 'priority' => $options['priority']);
        switch ($options['type']) {
            case 'color':
                $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, $option_key, $control_options));
                break;
            case 'et_coloralpha':
                $wp_customize->add_control(new ET_Color_Alpha_Control($wp_customize, $option_key, $control_options));
                break;
            case 'range':
                $control_options = array_merge($control_options, array('input_attrs' => $options['input_attrs']));
                $wp_customize->add_control(new ET_Range_Control($wp_customize, $option_key, $control_options));
                break;
            case 'radio':
                $control_options = array_merge($control_options, array('choices' => $options['choices']));
                $wp_customize->add_control($option_key, $control_options);
                break;
            case 'dropdown-font-styles':
                $control_options = array_merge($control_options, array('type' => 'select', 'choices' => et_extra_font_style_choices()));
                $wp_customize->add_control(new ET_Font_Style_Control($wp_customize, $option_key, $control_options));
                break;
            case 'dropdown-fonts':
                if (et_is_one_font_language()) {
                    break;
                }
                $control_options = array_merge($control_options, array('type' => 'select', 'choices' => et_dropdown_google_font_choices()));
                $wp_customize->add_control(new ET_Font_Select_Control($wp_customize, $option_key, $control_options));
                break;
            case 'select':
            default:
                $control_options = array_merge($control_options, array('choices' => $options['choices']));
                $wp_customize->add_control($option_key, $control_options);
                break;
        }
        $options['priority']++;
    }
}