get_setting( 'blogname' )->transport = 'refresh'; function airy_sanitize_checkbox( $checked ) { // Boolean check. return ( ( isset( $checked ) && true == $checked ) ? true : false ); } /* *************** */ /* */ /* Font Customizer */ /* */ /* *************** */ // PANEL $wp_customize->add_panel( 'airy_fonts_panel', array( 'title' => esc_html__( 'Fonts', 'airy' ), 'description' => esc_html__( 'Choose where to load fonts from.', 'airy' ), 'priority' => 30, ) ); // SECTIONS $wp_customize->add_section( 'airy_websafe_fonts' , array( 'panel' => 'airy_fonts_panel', 'title' => esc_html__( 'Web safe fonts', 'airy' ), 'priority' => 1, ) ); $wp_customize->add_section( 'airy_self_fonts' , array( 'panel' => 'airy_fonts_panel', 'title' => esc_html__( 'Self-hosted fonts', 'airy' ), 'priority' => 4, ) ); /* ************* */ /* Web safe font */ /* ************* */ // CHECKBOX $wp_customize->add_setting( 'airy_websafe_fonts_checkbox', array( 'capability' => 'edit_theme_options', 'default' => true, 'sanitize_callback' => 'airy_sanitize_checkbox', ) ); $wp_customize->add_control( 'airy_websafe_fonts_checkbox', array( 'type' => 'checkbox', 'section' => 'airy_websafe_fonts', 'label' => esc_html__( 'Enable Web safe fonts', 'airy' ), 'description' => esc_html__( 'Use web-safe fonts to speed up performance.', 'airy' ) ) ); //SETTINGS $wp_customize->add_setting( 'websafe_font', array( 'default' => '-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Open Sans", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif', 'sanitize_callback' => 'sanitize_text_field' ) ); $wp_customize->add_setting( 'websafe_font_2', array( 'default' => 'Georgia, serif', 'sanitize_callback' => 'sanitize_text_field' ) ); //CONTROLS $wp_customize->add_control( 'websafe_font', array( 'label' => esc_html__( 'Font Family', 'airy' ), 'section' => 'airy_websafe_fonts', 'settings' => 'websafe_font', 'type' => 'text', 'description' => esc_html__( 'Font family for headings (sans-serif):', 'airy' ) ) ); $wp_customize->add_control( 'websafe_font_2', array( 'label' => esc_html__( 'Font Family 2', 'airy' ), 'section' => 'airy_websafe_fonts', 'settings' => 'websafe_font_2', 'type' => 'text', 'description' => esc_html__( 'Font family for body copy (serif):', 'airy' ) ) ); /* ***************** */ /* Self-hosted Fonts */ /* ***************** */ // CHECKBOX $wp_customize->add_setting( 'airy_self_fonts_checkbox', array( 'capability' => 'edit_theme_options', 'default' => false, 'sanitize_callback' => 'airy_sanitize_checkbox', ) ); $wp_customize->add_control( 'airy_self_fonts_checkbox', array( 'type' => 'checkbox', 'section' => 'airy_self_fonts', 'label' => esc_html__( 'Enable self-hosted fonts', 'airy' ), 'description' => esc_html__( 'Use self-hosted fonts. Choose first font sans-serif for headings and second serif for copy. Upload the fonts to /fonts directory of the theme. Make sure the file name matches font name (eg. my-font.ttf = My Font).', 'airy' ) ) ); //SETTINGS $wp_customize->add_setting( 'self_font', array( 'default' => '', 'sanitize_callback' => 'sanitize_text_field' ) ); $wp_customize->add_setting( 'self_font_2', array( 'default' => '', 'sanitize_callback' => 'sanitize_text_field' ) ); //CONTROLS $wp_customize->add_control( 'self_font', array( 'label' => esc_html__( 'Font Name', 'airy' ), 'section' => 'airy_self_fonts', 'settings' => 'self_font', 'type' => 'text', 'description' => esc_html__( 'Font name for headings (sans-serif):', 'airy' ) ) ); $wp_customize->add_control( 'self_font_2', array( 'label' => esc_html__( 'Font Name 2', 'airy' ), 'section' => 'airy_self_fonts', 'settings' => 'self_font_2', 'type' => 'text', 'description' => esc_html__( 'Font name for body copy (serif):', 'airy' ) ) ); /* *************** */ /* */ /* Color Schemer */ /* */ /* *************** */ $wp_customize->add_setting( 'accent_color', array( 'default' => '#265CBF', 'sanitize_callback' => 'sanitize_hex_color' ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'accent_color', array( 'section' => 'colors', 'label' => esc_html__('Links', 'airy') ) ) ); $wp_customize->add_setting( 'text_color', array( 'default' => '#333333', 'sanitize_callback' => 'sanitize_hex_color' ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'text_color', array( 'section' => 'colors', 'label' => esc_html__('Text Color', 'airy') ) ) ); $wp_customize->add_setting( 'button_color', array( 'default' => '#333333', 'sanitize_callback' => 'sanitize_hex_color' ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'button_color', array( 'section' => 'colors', 'label' => esc_html__('Buttons', 'airy') ) ) ); $wp_customize->add_setting( 'meta_color', array( 'default' => '#727478', 'sanitize_callback' => 'sanitize_hex_color' ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'meta_color', array( 'section' => 'colors', 'label' => esc_html__('Meta Text', 'airy') ) ) ); $wp_customize->add_setting( 'line_color', array( 'default' => '#DFDFDF', 'sanitize_callback' => 'sanitize_hex_color' ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'line_color', array( 'section' => 'colors', 'label' => esc_html__('Borders', 'airy') ) ) ); $wp_customize->add_setting( 'block_color', array( 'default' => '#f5f5f5', 'sanitize_callback' => 'sanitize_hex_color' ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'block_color', array( 'section' => 'colors', 'label' => esc_html__('Blocks', 'airy') ) ) ); $colors = array(); $colors[] = array( 'slug'=>'accent_color', 'default' => '#265CBF', 'label' => esc_html__('Links', 'airy') ); $colors[] = array( 'slug'=>'text_color', 'default' => '#333333', 'label' => esc_html__('Text Color', 'airy') ); $colors[] = array( 'slug'=>'button_color', 'default' => '#333333', 'label' => esc_html__('Buttons', 'airy') ); $colors[] = array( 'slug'=>'meta_color', 'default' => '#727478', 'label' => esc_html__('Meta Text', 'airy') ); $colors[] = array( 'slug'=>'line_color', 'default' => '#DFDFDF', 'label' => esc_html__('Borders', 'airy') ); $colors[] = array( 'slug'=>'block_color', 'default' => '#f5f5f5', 'label' => esc_html__('Blocks', 'airy') ); } /** * Output settings CSS into the head. * */ function airy_customize_css() { $bg_color = get_background_color(); $accent_color = get_theme_mod('accent_color','#265CBF'); $text_color = get_theme_mod('text_color', '#333333'); $button_color = get_theme_mod('button_color', '#333333'); $meta_color = get_theme_mod('meta_color', '#727478'); $line_color = get_theme_mod('line_color', '#dfdfdf'); $block_color = get_theme_mod('block_color', '#f5f5f5'); $font = 'sans-serif'; $font2 = 'serif'; if ( get_theme_mod('airy_websafe_fonts_checkbox') == 1 ) { $font = sanitize_text_field(get_theme_mod('websafe_font')); $font2 = sanitize_text_field(get_theme_mod('websafe_font_2')); } if ( get_theme_mod('airy_self_fonts_checkbox') == 1 ) { $font = sanitize_text_field(get_theme_mod('self_font')); $font2 = sanitize_text_field(get_theme_mod('self_font_2')); $fonts_dir = get_template_directory_uri() . '/fonts/'; $font_file = str_replace(' ', '-', strtolower($font)); $font_file_2 = str_replace(' ', '-', strtolower($font2)); $airy_self_fonts_custom_css = " /* Embed Font */ @font-face { font-family: '{$font}'; src: url('{$fonts_dir}{$font_file}.woff2') format('woff2'), url('{$fonts_dir}{$font_file}.woff') format('woff'), url('{$fonts_dir}{$font_file}.ttf') format('truetype'); } @font-face { font-family: '{$font2}'; src: url('{$fonts_dir}{$font_file_2}.woff2') format('woff2'), url('{$fonts_dir}{$font_file_2}.woff') format('woff'), url('{$fonts_dir}{$font_file_2}.ttf') format('truetype'); } "; wp_add_inline_style( 'hybrid-style', $airy_self_fonts_custom_css ); wp_add_inline_style( 'wp-edit-blocks', $airy_self_fonts_custom_css ); } $airy_custom_css = " /* Font */ body, button, input, label { font-family: {$font}; } .editor-styles-wrapper, .editor-post-title__block .editor-post-title__input { font-family: {$font} !important; } em, article p, .editor-styles-wrapper p, article li, .editor-styles-wrapper li, article blockquote, .editor-styles-wrapper blockquote, article table, .editor-styles-wrapper table, article dl, .editor-styles-wrapper dl { font-family: {$font2}; } /* Colors */ :root { --bg-color: {$bg_color}; --accent-color: {$accent_color}; --text-color: {$text_color}; --button-color: {$button_color}; --meta-color: {$meta_color}; --line-color: {$line_color}; --block-color: {$block_color}; } "; wp_add_inline_style( 'hybrid-style', $airy_custom_css ); wp_add_inline_style( 'wp-edit-blocks', $airy_custom_css ); } /* Output settings CSS into the head. */ add_action( 'wp_enqueue_scripts', 'airy_customize_css', 30); add_action( 'admin_enqueue_scripts', 'airy_customize_css', 30);