get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; // Theme Settings $wp_customize->add_panel( 'brilliant_panel', array( 'title' => 'Theme Settings', 'priority' => 10, ) ); // General Section $wp_customize->add_section( 'general_section', array( 'title' => __( 'General', 'brilliant' ), 'priority' => 5, 'panel' => 'brilliant_panel', ) ); // Read More Link $wp_customize->add_setting( 'show_read_more', array( 'default' => 1, 'sanitize_callback' => 'brilliant_sanitize_checkbox', ) ); $wp_customize->add_control( 'show_read_more', array( 'label' => __( 'Display Read More Link', 'brilliant' ), 'section' => 'general_section', 'settings' => 'show_read_more', 'type' => 'checkbox', ) ); // Header Section $wp_customize->add_section( 'header_section', array( 'title' => __( 'Header', 'brilliant' ), 'priority' => 10, 'panel' => 'brilliant_panel', ) ); // Blog Section $wp_customize->add_section( 'blog_section', array( 'title' => __( 'Blog', 'brilliant' ), 'priority' => 15, 'panel' => 'brilliant_panel', 'description' => __( 'Settings for Blog Posts Index Page.', 'brilliant' ), ) ); // Blog Layout $wp_customize->add_setting( 'blog_layout', array( 'default' => 'blog-layout4', 'sanitize_callback' => 'brilliant_sanitize_choices', ) ); $wp_customize->add_control( 'blog_layout', array( 'label' => __( 'Layout', 'brilliant' ), 'section' => 'blog_section', 'settings' => 'blog_layout', 'type' => 'radio', 'choices' => array( 'blog-layout1' => __('Classic: Large Posts + Sidebar', 'brilliant'), 'blog-layout2' => __('Grid: Two Columns + Sidebar', 'brilliant'), 'blog-layout3' => __('First Overlay Post then Large + Sidebar', 'brilliant'), 'blog-layout4' => __('First Overlay Post then Grid + Sidebar', 'brilliant'), ), ) ); // Blog Excerpt Length $wp_customize->add_setting( 'blog_excerpt_length', array( 'default' => 25, 'sanitize_callback' => 'brilliant_sanitize_integer', ) ); $wp_customize->add_control( 'blog_excerpt_length', array( 'label' => __( 'Excerpt length', 'brilliant' ), 'section' => 'blog_section', 'settings' => 'blog_excerpt_length', 'type' => 'number', ) ); // Archives Section $wp_customize->add_section( 'archive_section', array( 'title' => __( 'Categories & Archives', 'brilliant' ), 'priority' => 20, 'panel' => 'brilliant_panel', 'description' => __( 'Settings for Category, Tag, Search and Archive Pages.', 'brilliant' ), ) ); // Archives Layout $wp_customize->add_setting( 'archive_layout', array( 'default' => 'archive-layout2', 'sanitize_callback' => 'brilliant_sanitize_choices', ) ); $wp_customize->add_control( 'archive_layout', array( 'label' => __( 'Layout', 'brilliant' ), 'section' => 'archive_section', 'settings' => 'archive_layout', 'type' => 'radio', 'choices' => array( 'archive-layout1' => __('Classic: Large Posts + Sidebar', 'brilliant'), 'archive-layout2' => __('Grid: Two Columns + Sidebar', 'brilliant'), ), ) ); // Archives Excerpt Length $wp_customize->add_setting( 'archive_excerpt_length', array( 'default' => 25, 'sanitize_callback' => 'brilliant_sanitize_integer', ) ); $wp_customize->add_control( 'archive_excerpt_length', array( 'label' => __( 'Excerpt length', 'brilliant' ), 'section' => 'archive_section', 'settings' => 'archive_excerpt_length', 'type' => 'number', ) ); // Post Section $wp_customize->add_section( 'post_section', array( 'title' => __( 'Post', 'brilliant' ), 'priority' => 25, 'panel' => 'brilliant_panel', ) ); // Feauted Image $wp_customize->add_setting( 'post_has_featured_image', array( 'default' => 1, 'sanitize_callback' => 'brilliant_sanitize_checkbox', ) ); $wp_customize->add_control( 'post_has_featured_image', array( 'label' => __( 'Display Featured Image', 'brilliant' ), 'section' => 'post_section', 'settings' => 'post_has_featured_image', 'type' => 'checkbox', ) ); // Featured Image Style $wp_customize->add_setting( 'post_featured_image_size', array( 'default' => 'overlay', 'sanitize_callback' => 'brilliant_sanitize_choices', ) ); $wp_customize->add_control( 'post_featured_image_size', array( 'description' => __( 'Featured Image Style', 'brilliant' ), 'section' => 'post_section', 'settings' => 'post_featured_image_size', 'type' => 'radio', 'choices' => array( 'onecolumn' => __('One Column', 'brilliant'), 'overlay' => __('Overlay (images must be at least 1160px)', 'brilliant'), ), 'active_callback' => 'brilliant_post_has_featured_image', ) ); // Author Bio $wp_customize->add_setting( 'show_author_bio', array( 'default' => '', 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'brilliant_sanitize_checkbox', ) ); $wp_customize->add_control( 'show_author_bio', array( 'label' => __( 'Display Author Bio', 'brilliant' ), 'section' => 'post_section', 'settings' => 'show_author_bio', 'type' => 'checkbox', ) ); // Page Section $wp_customize->add_section( 'page_section', array( 'title' => __( 'Page', 'brilliant' ), 'priority' => 30, 'panel' => 'brilliant_panel', ) ); // Feauted Image $wp_customize->add_setting( 'page_has_featured_image', array( 'default' => 1, 'sanitize_callback' => 'brilliant_sanitize_checkbox', ) ); $wp_customize->add_control( 'page_has_featured_image', array( 'label' => __( 'Display Featured Image', 'brilliant' ), 'section' => 'page_section', 'settings' => 'page_has_featured_image', 'type' => 'checkbox', ) ); // Featured Image Style $wp_customize->add_setting( 'page_featured_image_size', array( 'default' => 'overlay', 'sanitize_callback' => 'brilliant_sanitize_choices', ) ); $wp_customize->add_control( 'page_featured_image_size', array( 'description' => __( 'Featured Image Style', 'brilliant' ), 'section' => 'page_section', 'settings' => 'page_featured_image_size', 'type' => 'radio', 'choices' => array( 'onecolumn' => __('One Column', 'brilliant'), 'overlay' => __('Overlay (images must be at least 1160px)', 'brilliant'), ), 'active_callback' => 'brilliant_page_has_featured_image', ) ); // Logo Max Width (desktop) $wp_customize->add_setting( 'logo_width_lg', array( 'default' => 240, 'sanitize_callback' => 'brilliant_sanitize_integer', ) ); $wp_customize->add_control( 'logo_width_lg', array( 'label' => __( 'Logo Max Width (desktop)', 'brilliant' ), 'section' => 'title_tagline', 'settings' => 'logo_width_lg', 'type' => 'number', 'priority' => 9, ) ); // Logo Max Width (mobile) $wp_customize->add_setting( 'logo_width_sm', array( 'default' => 180, 'sanitize_callback' => 'brilliant_sanitize_integer', ) ); $wp_customize->add_control( 'logo_width_sm', array( 'label' => __( 'Logo Max Width (mobile)', 'brilliant' ), 'section' => 'title_tagline', 'settings' => 'logo_width_sm', 'type' => 'number', 'priority' => 9, ) ); // Accent Color $wp_customize->add_setting( 'accent_color', array( 'default' => '#e52e7a', 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'accent_color', array( 'label' => __( 'Accent Color', 'brilliant' ), 'section' => 'colors', 'settings' => 'accent_color', ) ) ); // Footer Background $wp_customize->add_setting( 'footer_bg', array( 'default' => '#1b2126', 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'footer_bg', array( 'label' => __( 'Footer background', 'brilliant' ), 'section' => 'colors', 'settings' => 'footer_bg', ) ) ); } add_action('customize_register', 'brilliant_theme_customizer'); /** * Sanitize Checkbox * */ function brilliant_sanitize_checkbox( $input ) { if ( $input == 1 ) { return 1; } else { return ''; } } /** * Sanitize Radio Buttons and Select Lists * */ function brilliant_sanitize_choices( $input, $setting ) { global $wp_customize; $control = $wp_customize->get_control( $setting->id ); if ( array_key_exists( $input, $control->choices ) ) { return $input; } else { return $setting->default; } } /** * Sanitize Numbers * */ function brilliant_sanitize_integer( $input ) { return intval( $input ); } /** * Checks if Single Post has featured image */ function brilliant_post_has_featured_image( $control ) { if ( $control->manager->get_setting('post_has_featured_image')->value() == 1 ) { return true; } else { return false; } } /** * Checks if Page has featured image */ function brilliant_page_has_featured_image( $control ) { if ( $control->manager->get_setting('page_has_featured_image')->value() == 1 ) { return true; } else { return false; } } /** * Get Contrast * */ function brilliant_get_brightness($hex) { // returns brightness value from 0 to 255 // strip off any leading # $hex = str_replace('#', '', $hex); $c_r = hexdec(substr($hex, 0, 2)); $c_g = hexdec(substr($hex, 2, 2)); $c_b = hexdec(substr($hex, 4, 2)); return (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; } /** * Add inline CSS for styles handled by the Theme customizer * */ function brilliant_add_styles() { $accent_color = esc_attr( get_option('accent_color') ); $footer_bg = esc_attr( get_option('footer_bg') ); $logo_w_desktop = esc_attr( get_theme_mod('logo_width_lg', 240) ); $logo_w_mobile = esc_attr( get_theme_mod('logo_width_sm', 180) ); $custom_styles = ""; // Accent Color if ( $accent_color != '' ) { $custom_styles .= " a, a:hover, a:focus, a:active, .site-info a:hover, .widget a:hover, .comment-metadata a:hover, .site-title a:hover, .entry-header h1 a:hover, .entry-header h2 a:hover, .posts-navigation a:hover, .cover .read-more, .large-post .read-more, .main-navigation li:hover > a, .main-navigation li:focus > a, .main-navigation .current_page_item > a, .main-navigation .current-menu-item > a, .main-navigation .current_page_ancestor > a, .main-navigation .current-menu-ancestor > a, .dropdown-toggle:hover, .dropdown-toggle:focus { color: {$accent_color}; } button, input[type='button'], input[type='reset'], input[type='submit'], .cover .read-more:hover, .large-post .read-more:hover, .sidebar .widget_tag_cloud a:hover, .reply a:hover { background-color: {$accent_color}; } .cover .read-more, .large-post .read-more, .reply a { border-color: {$accent_color}; }"; if ( brilliant_get_brightness($accent_color) > 155) { $custom_styles .= " button, input[type='button'], input[type='reset'], input[type='submit'], .cover .read-more:hover, .large-post .read-more:hover, .sidebar .widget_tag_cloud a:hover, .reply a:hover { color: rgba(0,0,0,.7); }"; } else { $custom_styles .= " button, input[type='button'], input[type='reset'], input[type='submit'], .cover .read-more:hover, .large-post .read-more:hover { color: #fff; }"; } } // if $accent_color // Footer Background if ( $footer_bg != '' ) { $custom_styles .= " .site-footer {background-color: {$footer_bg};}"; if ( brilliant_get_brightness($footer_bg) > 155) { $custom_styles .= " .site-footer { border-top: 1px solid rgba(0,0,0,.08); } .site-info, .site-credits, .site-footer .widget-area { color: rgba(0,0,0,.7); } .site-info a, .site-info a:hover, .site-footer .widget a, .site-footer .widget a:hover { color: rgba(0,0,0,.8); } .site-footer .widget-title { color: rgba(0,0,0,.8); } .site-footer .widget-area ul li { border-bottom-color: rgba(0,0,0,.05); } .site-footer .widget_tag_cloud a { border-color: rgba(0,0,0,.05); background-color: rgba(0,0,0,.05); }"; } } // if $footer_bg // Logo Size if ( $logo_w_mobile != '' ) { $custom_styles .= " @media screen and (max-width: 480px) { .custom-logo {max-width: px;} }"; } if ( $logo_w_desktop != '' ) { $custom_styles .= " @media screen and (min-width: 481px) { .custom-logo {max-width: px;} }"; } if ( $custom_styles != '' ) { wp_add_inline_style( 'brilliant-style', $custom_styles ); } } add_action( 'wp_enqueue_scripts', 'brilliant_add_styles' );