Example #1
0
/**
 * Registers Customizer sections, settings, and controls
 */
function tamatebako_fonts_customizer_register($wp_customize)
{
    /* Custom Control */
    tamatebako_include('modules/custom-fonts/customizer-control', true);
    /* Load All Google Fonts in Customizer */
    add_action('customize_controls_print_styles', 'tametebako_fonts_customize_styles');
    /* == CONFIG == */
    $config = tamatebako_fonts_config();
    $labels = tamatebako_fonts_label();
    /* Panel. */
    $wp_customize->add_panel('fonts', array('title' => esc_html($labels['fonts'])));
    /* Create Sections From Config */
    foreach ($config as $section => $section_data) {
        /* Section. */
        $wp_customize->add_section($section, array('title' => esc_html($section_data['label']), 'description' => isset($section_data['description']) ? $section_data['description'] : '', 'panel' => 'fonts'));
        /* Setting */
        $wp_customize->add_setting($section, array('default' => $section_data['default'], 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'tamatebako_fonts_sanitize'));
        /* Control */
        $wp_customize->add_control(new Tamatebako_Custom_Fonts_Customize($wp_customize, $section, array('section' => $section, 'settings' => $section, 'choices' => tamatebako_fonts_format_choices($section_data['fonts']))));
    }
}
Example #2
0
/**
 * Custom Font: Body Class Status
 */
function tamatebako_fonts_body_class($classes)
{
    /* Add active status */
    $classes[] = 'custom-fonts-active';
    /* Get fonts config */
    $config = tamatebako_fonts_config();
    /* Foreach setting */
    foreach ($config as $section => $section_data) {
        /* format font name */
        $font = get_theme_mod($section, $section_data['default']);
        $font = 'tf-' . $section . '-' . $font;
        $font = strtolower($font);
        $font = str_replace(' ', '-', $font);
        /* Add class */
        $classes[] = sanitize_html_class($font);
    }
    return array_unique($classes);
}
Example #3
0
/**
 * Ajax Callback
 */
function tamatebako_fonts_mce_css_ajax_callback()
{
    /* Var */
    $css = '';
    $settings = tamatebako_fonts_mce_setting();
    $config = tamatebako_fonts_config();
    foreach ($settings as $setting) {
        $font = get_theme_mod($setting, $config[$setting]['default']);
        $target_element = $config[$setting]['target'];
        $font_family = tamatebako_get_font_family($font);
        $css .= "{$target_element}{font-family:{$font_family};}";
    }
    header('Content-type: text/css');
    echo $css;
    die;
}