/** * Skola Theme Customizer * * @package Skola */ if ( ! function_exists( 'skola_sass_hex_to_rgba' ) ) { function skola_sass_hex_to_rgba( $hex, $alpa = '' ) { $hex = sanitize_hex_color( $hex ); preg_match( '/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i', $hex, $matches ); for ( $i = 1; $i <= 3; $i++ ) { $matches[ $i ] = hexdec( $matches[ $i ] ); } if ( ! empty( $alpa ) ) { $rgb = 'rgba(' . $matches[1] . ', ' . $matches[2] . ', ' . $matches[3] . ', ' . $alpa . ')'; } else { $rgb = 'rgba(' . $matches[1] . ', ' . $matches[2] . ', ' . $matches[3] . ')'; } return $rgb; } } if ( ! function_exists( 'skola_sass_yiq' ) ) { function skola_sass_yiq( $hex ) { $hex = sanitize_hex_color( $hex ); $length = strlen( $hex ); if ( $length < 5 ) { $hex = ltrim( $hex, '#' ); $hex = '#' . $hex . $hex; } preg_match( '/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i', $hex, $matches ); for ( $i = 1; $i <= 3; $i++ ) { $matches[ $i ] = hexdec( $matches[ $i ] ); } $yiq = ( ( $matches[1] * 299 ) + ( $matches[2] * 587 ) + ( $matches[3] * 114 ) ) / 1000; return ( $yiq >= 128 ) ? '#000' : '#fff'; } } /** * Get all of the skola theme colors. * * @return array $skola_theme_colors The skola Theme Colors. */ if ( ! function_exists( 'skola_get_theme_colors' ) ) { function skola_get_theme_colors() { $skola_theme_colors = array( 'primary_color' => get_theme_mod( 'skola_primary_color', apply_filters( 'skola_default_primary_color', '#090761' ) ), ); return apply_filters( 'skola_get_theme_colors', $skola_theme_colors ); } } /** * Get Customizer Color css. * * @see skola_get_custom_color_css() * @return array $styles the css */ if ( ! function_exists( 'skola_get_custom_color_css' ) ) { function skola_get_custom_color_css() { $skola_theme_colors = skola_get_theme_colors(); $primary_color = $skola_theme_colors['primary_color']; $primary_color_yiq = skola_sass_yiq( $primary_color ); $primary_color_darken_10p = skola_adjust_color_brightness( $primary_color, -10 ); $primary_color_darken_15p = skola_adjust_color_brightness( $primary_color, -15 ); $primary_color_lighten_20p = skola_adjust_color_brightness( $primary_color, 20 ); $styles = ' /* * Primary Color */ '; return apply_filters( 'skola_get_custom_color_css', $styles ); } } /** * Add CSS in for styles handled by the theme customizer * * @since 1.0.0 * @return void */ if ( ! function_exists( 'skola_enqueue_custom_color_css' ) ) { function skola_enqueue_custom_color_css() { if ( get_theme_mod( 'skola_enable_custom_color', 'no' ) === 'yes' ) { $skola_theme_colors = skola_get_theme_colors(); $primary_color = $skola_theme_colors['primary_color']; $primary_color_yiq = skola_sass_yiq( $primary_color ); $primary_color_darken_10p = skola_adjust_color_brightness( $primary_color, -10 ); $primary_color_darken_15p = skola_adjust_color_brightness( $primary_color, -15 ); $primary_color_lighten_10p = skola_adjust_color_brightness( $primary_color, 10 ); $primary_color_opacity = skola_sass_hex_to_rgba( $primary_color, '.05' ); $primary_color_outline_35 = skola_sass_hex_to_rgba( $primary_color, '.35' ); $primary_color_bg_outline = skola_sass_hex_to_rgba( $primary_color, '.08' ); $primary_color_outline_70 = skola_sass_hex_to_rgba( $primary_color, '.7' ); $primary_color_outline_15 = skola_sass_hex_to_rgba( $primary_color, '.15' ); $start_percent = '0%'; $end_percent = '100%'; $mid_percent = '30%'; $color_root = ':root { --sk-primary: ' . $skola_theme_colors['primary_color'] . '; --sk-primary-bg-d : ' . $primary_color_darken_10p . '; --sk-primary-border-d: ' . $primary_color_darken_15p . '; --sk-primary-o-5: ' . $primary_color_opacity . '; --sk-primary-outline-35: ' . $primary_color_outline_35 . '; --sk-primary-outline-bg: ' . $primary_color_bg_outline . '; --sk-primary-bg-gradient: linear-gradient( to right, ' . $primary_color . ' ' . $start_percent . ', ' . $primary_color . ' ' . $mid_percent . ', ' . $primary_color_lighten_10p . ' ' . $end_percent . '); --sk-primary-outline-70: ' . $primary_color_outline_70 . '; --sk-primary-outline-15: ' . $primary_color_outline_15 . ';}'; $styles = $color_root . skola_get_custom_color_css(); wp_add_inline_style( 'skola-color', $styles ); } } } add_action( 'wp_enqueue_scripts', 'skola_enqueue_custom_color_css', 130 );