$default_background_color, ) ) ); } add_action( 'after_setup_theme', 'blogolife_custom_background' ); /*------------------------------------------------------------ Adds postMessage support for site title and description for the Customizer. ============================================================*/ function blogolife_customize_register( $wp_customize ) { $color_scheme = blogolife_get_color_scheme(); // Add color scheme setting and control. $wp_customize->add_setting( 'color_scheme', array( 'default' => 'default', 'sanitize_callback' => 'blogolife_sanitize_color_scheme', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'color_scheme', array( 'label' => __( 'Base Color Scheme', 'blogolife' ), 'section' => 'colors', 'type' => 'select', 'choices' => blogolife_get_color_scheme_choices(), 'priority' => 1, ) ); // Add page background color setting and control. $wp_customize->add_setting( 'page_background_color', array( 'default' => $color_scheme[1], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'page_background_color', array( 'label' => __( 'Page Background Color', 'blogolife' ), 'section' => 'colors', ) ) ); // Remove the core header textcolor control, as it shares the main text color. $wp_customize->remove_control( 'header_textcolor' ); // Add Primary color setting and control. $wp_customize->add_setting( 'primary_color', array( 'default' => $color_scheme[2], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'primary_color', array( 'label' => __( 'Primary Color', 'blogolife' ), 'section' => 'colors', ) ) ); // Add Secondary color setting and control. $wp_customize->add_setting( 'secondary_color', array( 'default' => $color_scheme[3], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'secondary_color', array( 'label' => __( 'Secondary Color', 'blogolife' ), 'section' => 'colors', ) ) ); // Add text color setting and control. $wp_customize->add_setting( 'text_color', array( 'default' => $color_scheme[4], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'text_color', array( 'label' => __( 'Text Color', 'blogolife' ), 'section' => 'colors', ) ) ); // Add blog title color setting and control. $wp_customize->add_setting( 'title_color', array( 'default' => $color_scheme[5], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'title_color', array( 'label' => __( 'Site Title Color', 'blogolife' ), 'section' => 'colors', ) ) ); } add_action( 'customize_register', 'blogolife_customize_register', 11 ); /*------------------------------------------------------------ Registers color schemes for BlogoLife. The order of colors in a colors array: 1. Main Background Color. 2. Page Background Color. 3. Primary Color. 4. Secondary Color. 5. Main Text Color. 6. Site Title Text Color. @return array An associative array of color scheme options. ============================================================*/ function blogolife_get_color_schemes() { /*------------------------------------------------------------ Filter the color schemes The default schemes include 'default', 'black', 'blue', 'green', 'orange' and 'pink'. ============================================================*/ return apply_filters( 'blogolife_color_schemes', array( 'default' => array( 'label' => __( 'Default', 'blogolife' ), 'colors' => array( '#ffffff', '#ffffff', '#b41423', '#e2192c', '#666666', '#b41423', ), ), 'black' => array( 'label' => __( 'Black', 'blogolife' ), 'colors' => array( '#f3f3f3', '#ffffff', '#212121', '#525252', '#666666', '#212121', ), ), 'blue' => array( 'label' => __( 'Blue', 'blogolife' ), 'colors' => array( '#ffffff', '#ffffff', '#007fff', '#00aaff', '#666666', '#007fff', ), ), 'green' => array( 'label' => __( 'Green', 'blogolife' ), 'colors' => array( '#ffffff', '#ffffff', '#228b22', '#32cd32', '#666666', '#228b22', ), ), 'orange' => array( 'label' => __( 'Orange', 'blogolife' ), 'colors' => array( '#ffffff', '#ffffff', '#fa6f1c', '#fab035', '#666666', '#fa6f1c', ), ), 'pink' => array( 'label' => __( 'Pink', 'blogolife' ), 'colors' => array( '#ffffff', '#ffffff', '#c504a8', '#fa1cb4', '#666666', '#c504a8', ), ), ) ); } /*------------------------------------------------------------ Retrieves the current BlogoLife color scheme. Create your own blogolife_get_color_scheme() function to override in a child theme. @return array An associative array of either the current or default color scheme HEX values. ============================================================*/ if ( ! function_exists( 'blogolife_get_color_scheme' ) ) : function blogolife_get_color_scheme() { $color_scheme_option = get_theme_mod( 'color_scheme', 'default' ); $color_schemes = blogolife_get_color_schemes(); if ( array_key_exists( $color_scheme_option, $color_schemes ) ) { return $color_schemes[ $color_scheme_option ]['colors']; } return $color_schemes['default']['colors']; } endif; // blogolife_get_color_scheme /*------------------------------------------------------------ Retrieves an array of color scheme choices registered for BlogoLife. Create your own blogolife_get_color_scheme_choices() function to override in a child theme. @return array Array of color schemes. ============================================================*/ if ( ! function_exists( 'blogolife_get_color_scheme_choices' ) ) : function blogolife_get_color_scheme_choices() { $color_schemes = blogolife_get_color_schemes(); $color_scheme_control_options = array(); foreach ( $color_schemes as $color_scheme => $value ) { $color_scheme_control_options[ $color_scheme ] = $value['label']; } return $color_scheme_control_options; } endif; // blogolife_get_color_scheme_choices /*------------------------------------------------------------ Handles sanitization for BlogoLife color schemes. Create your own blogolife_sanitize_color_scheme() function to override in a child theme. ============================================================*/ if ( ! function_exists( 'blogolife_sanitize_color_scheme' ) ) : function blogolife_sanitize_color_scheme( $value ) { $color_schemes = blogolife_get_color_scheme_choices(); if ( ! array_key_exists( $value, $color_schemes ) ) { return 'default'; } return $value; } endif; // blogolife_sanitize_color_scheme /*------------------------------------------------------------ Enqueues front-end CSS for color scheme. ============================================================*/ function blogolife_color_scheme_css() { $color_scheme_option = get_theme_mod( 'color_scheme', 'default' ); // Don't do anything if the default color scheme is selected. if ( 'default' === $color_scheme_option ) { return; } $color_scheme = blogolife_get_color_scheme(); $title_color_rgb = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.7)', blogolife_hex2rgb( $color_scheme[5] ) ); // If we get this far, we have a custom color scheme. $colors = array( 'background_color' => $color_scheme[0], 'page_background_color' => $color_scheme[1], 'primary_color' => $color_scheme[2], 'secondary_color' => $color_scheme[3], 'text_color' => $color_scheme[4], 'title_color' => $color_scheme[5], 'title_color_rgb' => $title_color_rgb, ); $color_scheme_css = blogolife_get_color_scheme_css( $colors ); wp_add_inline_style( 'blogolife-style', $color_scheme_css ); } add_action( 'wp_enqueue_scripts', 'blogolife_color_scheme_css' ); /*------------------------------------------------------------ Binds the JS listener to make Customizer color_scheme control. Passes color scheme data as colorScheme global. ============================================================*/ function blogolife_customize_control_js() { wp_enqueue_script( 'color-scheme-control', get_template_directory_uri() . '/assets/scripts/color-scheme-control.js', array( 'customize-controls', 'iris', 'underscore', 'wp-util' ), blogolife_get_theme_version(), true ); wp_localize_script( 'color-scheme-control', 'colorScheme', blogolife_get_color_schemes() ); } add_action( 'customize_controls_enqueue_scripts', 'blogolife_customize_control_js' ); /*------------------------------------------------------------ Binds JS handlers to make the Customizer preview reload changes asynchronously. ============================================================*/ function blogolife_customize_preview_js() { wp_enqueue_script( 'blogolife-customize-preview', get_template_directory_uri() . '/assets/scripts/customize-preview.js', array( 'customize-preview' ), blogolife_get_theme_version(), true ); } add_action( 'customize_preview_init', 'blogolife_customize_preview_js' ); /*------------------------------------------------------------ Returns CSS for the color schemes. @param array $colors Color scheme colors. @return string Color scheme CSS. ============================================================*/ function blogolife_get_color_scheme_css( $colors ) { $colors = wp_parse_args( $colors, array( 'background_color' => '', 'page_background_color' => '', 'primary_color' => '', 'secondary_color' => '', 'text_color' => '', 'title_color' => '', 'title_color_rgb' => '', ) ); return << a[aria-selected=true], #tabs-widget-lcp .tabs .tabs-title > a:focus, #tabs-widget-lcp .tabs-content .tabs-panel-comments li .comment_content a:hover, .woocommerce .woocommerce-info:before, .woocommerce .woocommerce-message:before { color: {$colors['primary_color']}; } input[type=submit], article .entry-content blockquote, .woocommerce ul.products li.product .button, .woocommerce #respond input#submit, .woocommerce a.button, .woocommerce a.button.alt, .woocommerce button.button, .woocommerce button.button.alt, .woocommerce button.button.alt:disabled, .woocommerce button.button.alt:disabled[disabled], .woocommerce input.button.alt, .woocommerce input.button, .woocommerce .quantity input[type="number"], .woocommerce .woocommerce-info, .woocommerce .woocommerce-message { border-color: {$colors['primary_color']}; } article.sticky:before, .blogolife_main_menu.dropdown.menu .submenu, .blogolife-gradient:before { border-color: {$colors['primary_color']} transparent; } /* Secondary color */ input[type=submit]:hover, input[type=submit]:focus, .widget_calendar tbody a:hover , .widget_calendar tbody a:focus, .pagination .current, .post-nav-attachment .post-nav-prev-attachment a:hover, .post-nav-attachment .post-nav-next-attachment a:hover, .orbit-previous:hover, .orbit-previous:focus, .orbit-next:hover, .orbit-next:focus, .widget_price_filter.woocommerce .price_slider_wrapper .ui-widget-content, .woocommerce ul.products li.product .button:hover, .woocommerce ul.products li.product .button:focus, .woocommerce #respond input#submit:hover, .woocommerce #respond input#submit:focus, .woocommerce a.button:hover, .woocommerce a.button:focus, .woocommerce a.button.alt:hover, .woocommerce a.button.alt:focus, .woocommerce button.button:hover, .woocommerce button.button:focus, .woocommerce button.button.alt:hover, .woocommerce button.button.alt:focus, .woocommerce button.button.alt:disabled:hover, .woocommerce button.button.alt:disabled:focus, .woocommerce button.button.alt:disabled[disabled]:hover, .woocommerce button.button.alt:disabled[disabled]:focus, .woocommerce input.button.alt:hover, .woocommerce input.button.alt:focus, .woocommerce input.button:hover, .woocommerce input.button:focus { background-color: {$colors['secondary_color']}; } a:focus, a:hover, article .entry-footer a:hover, article .entry-footer .f-link:hover a:before { color: {$colors['secondary_color']}; } input[type=submit]:hover, input[type=submit]:focus, .woocommerce ul.products li.product .button:hover, .woocommerce ul.products li.product .button:focus, .woocommerce #respond input#submit:hover, .woocommerce #respond input#submit:focus, .woocommerce a.button:hover, .woocommerce a.button:focus, .woocommerce a.button.alt:hover, .woocommerce a.button.alt:focus, .woocommerce button.button:hover, .woocommerce button.button:focus, .woocommerce button.button.alt:hover, .woocommerce button.button.alt:focus, .woocommerce button.button.alt:disabled:hover, .woocommerce button.button.alt:disabled:focus, .woocommerce button.button.alt:disabled[disabled]:hover, .woocommerce button.button.alt:disabled[disabled]:focus, .woocommerce input.button.alt:hover, .woocommerce input.button.alt:focus, .woocommerce input.button:hover, .woocommerce input.button:focus { border-color: {$colors['secondary_color']}; } /* Text color */ body, h1, h2, h3, h4, h5, h6, label, tfoot, thead, .wp-caption .wp-caption-text { color: {$colors['text_color']}; } /* Site title color */ #site-title a { color: {$colors['title_color']}; } #site-description { color: {$colors['title_color_rgb']}; } CSS; } /*------------------------------------------------------------ Outputs an Underscore template for generating CSS for the color scheme. ============================================================*/ function blogolife_color_scheme_css_template() { $colors = array( 'background_color' => '{{ data.background_color }}', 'page_background_color' => '{{ data.page_background_color }}', 'primary_color' => '{{ data.primary_color }}', 'secondary_color' => '{{ data.secondary_color }}', 'text_color' => '{{ data.text_color }}', 'title_color' => '{{ data.title_color }}', 'title_color' => '{{ data.title_color }}', ); ?> a[aria-selected=true], #tabs-widget-lcp .tabs .tabs-title > a:focus, #tabs-widget-lcp .tabs-content .tabs-panel-comments li .comment_content a:hover, .woocommerce .woocommerce-info:before, .woocommerce .woocommerce-message:before { color: %1$s; } input[type=submit], article .entry-content blockquote, .woocommerce ul.products li.product .button, .woocommerce #respond input#submit, .woocommerce a.button, .woocommerce a.button.alt, .woocommerce button.button, .woocommerce button.button.alt, .woocommerce button.button.alt:disabled, .woocommerce button.button.alt:disabled[disabled], .woocommerce input.button.alt, .woocommerce input.button, .woocommerce .quantity input[type="number"], .woocommerce .woocommerce-info, .woocommerce .woocommerce-message { border-color: %1$s; } article.sticky:before, .blogolife_main_menu.dropdown.menu .submenu, .blogolife-gradient:before { border-color: %1$s transparent; } /* Gradient +p */ .blogolife-gradient { background-color: %1$s; background: -webkit-gradient(linear, left top, left bottom, from(%1$s), to(%2$s)); background: -o-linear-gradient(top, %1$s, %2$s); background: -moz-linear-gradient(top, %1$s, %2$s); background: -ms-linear-gradient(top, %1$s, %2$s); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="%1$s", endColorstr="%2$s", GradientType=0 ); } /* Menu +p */ .blogolife_main_menu.dropdown.menu a:hover, .blogolife_main_menu.dropdown.menu .current-menu-item a, .blogolife_main_menu.dropdown.menu .submenu, .blogolife_mobile_menu.vertical.menu a:hover { background-color: %2$s; background: -webkit-gradient(linear, left top, left bottom, from(%2$s), to(%1$s)); background: -o-linear-gradient(top, %2$s, %1$s); background: -moz-linear-gradient(top, %2$s, %1$s); background: -ms-linear-gradient(top, %2$s, %1$s); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="%2$s", endColorstr="%1$s", GradientType=0 ); } '; wp_add_inline_style( 'blogolife-style', sprintf( $css, $primary_color, $secondary_color ) ); } add_action( 'wp_enqueue_scripts', 'blogolife_primary_color_css', 11 ); /*------------------------------------------------------------ Enqueues front-end CSS for the Secondary color. ============================================================*/ function blogolife_secondary_color_css() { $color_scheme = blogolife_get_color_scheme(); $default_color_primary = $color_scheme[2]; $default_color_secondary = $color_scheme[3]; $primary_color = get_theme_mod( 'primary_color', $default_color_primary ); $secondary_color = get_theme_mod( 'secondary_color', $default_color_secondary ); // Don't do anything if the current color is the default. if ( $secondary_color === $default_color_secondary ) { return; } $css = ' /* Secondary color +s */ input[type=submit]:hover, input[type=submit]:focus, .widget_calendar tbody a:hover , .widget_calendar tbody a:focus, .pagination .current, .post-nav-attachment .post-nav-prev-attachment a:hover, .post-nav-attachment .post-nav-next-attachment a:hover, .orbit-previous:hover, .orbit-previous:focus, .orbit-next:hover, .orbit-next:focus, .widget_price_filter.woocommerce .price_slider_wrapper .ui-widget-content, .woocommerce ul.products li.product .button:hover, .woocommerce ul.products li.product .button:focus, .woocommerce #respond input#submit:hover, .woocommerce #respond input#submit:focus, .woocommerce a.button:hover, .woocommerce a.button:focus, .woocommerce a.button.alt:hover, .woocommerce a.button.alt:focus, .woocommerce button.button:hover, .woocommerce button.button:focus, .woocommerce button.button.alt:hover, .woocommerce button.button.alt:focus, .woocommerce button.button.alt:disabled:hover, .woocommerce button.button.alt:disabled:focus, .woocommerce button.button.alt:disabled[disabled]:hover, .woocommerce button.button.alt:disabled[disabled]:focus, .woocommerce input.button.alt:hover, .woocommerce input.button.alt:focus, .woocommerce input.button:hover, .woocommerce input.button:focus { background-color: %1$s; } a:focus, a:hover, article .entry-footer a:hover, article .entry-footer .f-link:hover a:before{ color: %1$s; } input[type=submit]:hover, input[type=submit]:focus, .woocommerce ul.products li.product .button:hover, .woocommerce ul.products li.product .button:focus, .woocommerce #respond input#submit:hover, .woocommerce #respond input#submit:focus, .woocommerce a.button:hover, .woocommerce a.button:focus, .woocommerce a.button.alt:hover, .woocommerce a.button.alt:focus, .woocommerce button.button:hover, .woocommerce button.button:focus, .woocommerce button.button.alt:hover, .woocommerce button.button.alt:focus, .woocommerce button.button.alt:disabled:hover, .woocommerce button.button.alt:disabled:focus, .woocommerce button.button.alt:disabled[disabled]:hover, .woocommerce button.button.alt:disabled[disabled]:focus, .woocommerce input.button.alt:hover, .woocommerce input.button.alt:focus, .woocommerce input.button:hover, .woocommerce input.button:focus { border-color: %1$s; } /* Gradient +s */ .blogolife-gradient { background-color: %2$s; background: -webkit-gradient(linear, left top, left bottom, from(%2$s), to(%1$s)); background: -o-linear-gradient(top, %2$s, %1$s); background: -moz-linear-gradient(top, %2$s, %1$s); background: -ms-linear-gradient(top, %2$s, %1$s); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="%2$s", endColorstr="%1$s", GradientType=0 ); } /* Menu +s */ .blogolife_main_menu.dropdown.menu a:hover, .blogolife_main_menu.dropdown.menu .current-menu-item a, .blogolife_main_menu.dropdown.menu .submenu, .blogolife_mobile_menu.vertical.menu a:hover { background-color: %1$s; background: -webkit-gradient(linear, left top, left bottom, from(%1$s), to(%2$s)); background: -o-linear-gradient(top, %1$s, %2$s); background: -moz-linear-gradient(top, %1$s, %2$s); background: -ms-linear-gradient(top, %1$s, %2$s); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="%1$s", endColorstr="%2$s", GradientType=0 ); } '; wp_add_inline_style( 'blogolife-style', sprintf( $css, $secondary_color, $primary_color ) ); } add_action( 'wp_enqueue_scripts', 'blogolife_secondary_color_css', 11 ); /*------------------------------------------------------------ Enqueues front-end CSS for the Text color. ============================================================*/ function blogolife_text_color_css() { $color_scheme = blogolife_get_color_scheme(); $default_color = $color_scheme[4]; $text_color = get_theme_mod( 'text_color', $default_color ); // Don't do anything if the current color is the default. if ( $text_color === $default_color ) { return; } $css = ' /* Text color + */ body, h1, h2, h3, h4, h5, h6, label, tfoot, thead, .wp-caption .wp-caption-text { color: %1$s; } '; wp_add_inline_style( 'blogolife-style', sprintf( $css, $text_color ) ); } add_action( 'wp_enqueue_scripts', 'blogolife_text_color_css', 11 ); /*------------------------------------------------------------ Enqueues front-end CSS for the Title color. ============================================================*/ function blogolife_title_color_css() { $color_scheme = blogolife_get_color_scheme(); $default_color = $color_scheme[5]; $title_color = get_theme_mod( 'title_color', $default_color ); $title_color_rgb = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.7)', blogolife_hex2rgb( $title_color ) ); //var_dump($title_color_rgb); // Don't do anything if the current color is the default. if ( $title_color === $default_color ) { return; } $css = ' /* Site title color */ #site-title a { color: %1$s; } #site-description { color: %2$s; } '; wp_add_inline_style( 'blogolife-style', sprintf( $css, $title_color, $title_color_rgb ) ); } add_action( 'wp_enqueue_scripts', 'blogolife_title_color_css', 11 );