/** * Add custom CSS rules to the head, applying our custom styles */ function custom_css() { $color = $this->get_admin_colors(); $config = Kirki::config(); $color_font = false; $color_accent = $config->get('color_accent', $color['icon_colors']['focus']); $color_back = $config->get('color_back', '#ffffff'); $color_font = 170 > \Kirki_Color::get_brightness($color_back) ? '#f2f2f2' : '#222'; $styles = '<style>'; // Background styles $styles .= '#customize-controls .wp-full-overlay-sidebar-content{background-color:' . $color_back . ';}'; $styles .= '#customize-theme-controls .accordion-section-title, #customize-info .accordion-section-title,#customize-info .accordion-section-title:hover,#customize-info.open .accordion-section-title{background-color:' . $color_back . ';color:' . $color_font . ';}'; $styles .= '#customize-theme-controls .control-section .accordion-section-title:hover,#customize-theme-controls .control-section .accordion-section-title:focus,.control-section.control-panel>.accordion-section-title:after{background-color:' . \Kirki_Color::adjust_brightness($color_back, -10) . ';color:' . $color_font . ';}'; $styles .= '#customize-theme-controls .control-section.control-panel>h3.accordion-section-title:focus:after, #customize-theme-controls .control-section.control-panel>h3.accordion-section-title:hover:after{background-color:' . \Kirki_Color::adjust_brightness($color_back, -20) . ';color:' . $color_font . ';}'; $styles .= '#customize-theme-controls .control-section.open .accordion-section-title{background-color:' . $color_accent . ' !important;color:' . $color_font . ' !important;}'; // Tooltip styles // $styles .= 'li.customize-control a.button.tooltip.hint--left {color:' . $color_accent . ';}'; // Image-Radio styles $styles .= '.customize-control-radio-image .image.ui-buttonset label.ui-state-active {border-color:' . $color_accent . ';}'; // Buttonset-Radio styles $styles .= '.customize-control-radio-buttonset label.ui-state-active{background-color:' . $color_accent . ';color:' . $color_font . ';}'; // Slider Controls $styles .= '.customize-control-slider .ui-slider .ui-slider-handle{background-color:' . $color_accent . ';border-color:' . $color_accent . ';}'; // Switch Controls $styles .= '.customize-control-switch .Switch .On, .customize-control-toggle .Switch .On{color:' . $color_accent . ';}'; // Toggle Controls $styles .= '.customize-control-switch .Switch.Round.On, .customize-control-toggle .Switch.Round.On{background-color:' . \Kirki_Color::adjust_brightness($color_accent, -10) . ';}'; // Sortable Controls $styles .= '.customize-control-sortable ul.ui-sortable li .dashicons.visibility{color:' . $color_accent . ';}'; // Palette Controls $styles .= '.customize-control-palette label.ui-state-active.ui-button.ui-widget span.ui-button-text {border-color:' . $color_accent . ';}'; $styles .= '</style>'; echo $styles; }
public function test_get_rgb() { $this->assertEquals('rgb(255,255,255)', Kirki_Color::get_rgb('#ffffff')); $this->assertEquals('rgb(0,0,0)', Kirki_Color::get_rgb('#000000')); $this->assertEquals('rgb(255,0,0)', Kirki_Color::get_rgb('#ff0000')); $this->assertEquals('rgb(0,255,0)', Kirki_Color::get_rgb('#00ff00')); $this->assertEquals('rgb(0,0,255)', Kirki_Color::get_rgb('#0000ff')); }
/** * Build an array of the available variables. * These variables are basically the variables.less file from bootstrap, * formatted as an array. */ function maera_bootstrap_get_variables() { $color = get_theme_mod('body_bg_color', '#ffffff'); $color = false !== strpos($color, 'rgba') ? Kirki_Color::rgba2hex($color) : $color; $body_obj = new Jetpack_Color($color); $body_bg = '#' . $body_obj->toHex(); $body_lum = $body_obj->toLuminosity(); $color = get_theme_mod('color_brand_primary', '#428bca'); $color = false !== strpos($color, 'rgba') ? Kirki_Color::rgba2hex($color) : $color; $b_p_obj = new Jetpack_Color($color); $brand_primary = '#' . $b_p_obj->toHex(); $brand_primary_lum = $b_p_obj->toLuminosity(); $color_success = new Jetpack_Color('#5cb85c'); $brand_success = '#' . $color_success->getReadableContrastingColor($body_obj, 1.5)->toHex(); $b_s_obj = new Jetpack_Color($brand_success); $brand_success_lum = $b_s_obj->toLuminosity(); $color_warning = new Jetpack_Color('#f0ad4e'); $brand_warning = '#' . $color_warning->getReadableContrastingColor($body_obj, 1.5)->toHex(); $b_w_obj = new Jetpack_Color($brand_warning); $brand_warning_lum = $b_w_obj->toLuminosity(); $color_danger = new Jetpack_Color('#d9534f'); $brand_danger = '#' . $color_danger->getReadableContrastingColor($body_obj, 1.5)->toHex(); $b_d_obj = new Jetpack_Color($brand_danger); $brand_danger_lum = $b_d_obj->toLuminosity(); $color_info = new Jetpack_Color('#5bc0de'); $brand_info = '#' . $color_info->getReadableContrastingColor($body_obj, 1.5)->toHex(); $b_i_obj = new Jetpack_Color($brand_info); $brand_info_lum = $b_i_obj->toLuminosity(); $color = get_theme_mod('navbar_bg', '#f8f8f8'); $color = false !== strpos($color, 'rgba') ? Kirki_Color::rgba2hex($color) : $color; $nav_col_obj = new Jetpack_Color($color); $color = get_theme_mod('jumbo_bg', '#ffffff'); $color = false !== strpos($color, 'rgba') ? Kirki_Color::rgba2hex($color) : $color; $jumbotron_obj = new Jetpack_Color($color); $navbar_border = 0.6 < $brand_primary_lum ? 'lighten(@navbar-default-bg, 6.5%)' : 'darken(@navbar-default-bg, 6.5%)'; $screen_sm = filter_var(get_theme_mod('screen_tablet', 768), FILTER_SANITIZE_NUMBER_INT); $screen_md = filter_var(get_theme_mod('screen_desktop', 992), FILTER_SANITIZE_NUMBER_INT); $screen_lg = filter_var(get_theme_mod('screen_large_desktop', 1200), FILTER_SANITIZE_NUMBER_INT); $gutter = filter_var(get_theme_mod('gutter', 30), FILTER_SANITIZE_NUMBER_INT); $gutter = $gutter < 2 ? 2 : $gutter; $site_style = get_theme_mod('site_style', 'wide'); $screen_xs = $site_style == 'static' ? '50px' : '480px'; $screen_sm = $site_style == 'static' ? '50px' : $screen_sm; $screen_md = $site_style == 'static' ? '50px' : $screen_md; $gfb = get_theme_mod('grid_float_breakpoint', 'screen_sm_min'); $grid_float_breakpoint = isset($gfb) ? $gfb : '@screen-sm-min'; $grid_float_breakpoint = $gfb == 'min' ? '10px' : $grid_float_breakpoint; $grid_float_breakpoint = $gfb == 'screen_xs_min' ? '@screen-xs-min' : $grid_float_breakpoint; $grid_float_breakpoint = $gfb == 'screen_sm_min' ? '@screen-sm-min' : $grid_float_breakpoint; $grid_float_breakpoint = $gfb == 'screen_md_min' ? '@screen-md-min' : $grid_float_breakpoint; $grid_float_breakpoint = $gfb == 'screen_lg_min' ? '@screen-lg-min' : $grid_float_breakpoint; $grid_float_breakpoint = $gfb == 'max' ? '9999px' : $grid_float_breakpoint; $grid_float_breakpoint = $gfb == 'screen-lg-min' ? '0 !important' : $grid_float_breakpoint; $font_size_base = get_theme_mod('font_base_size', 14) . 'px'; $variables = array('gray-base' => 0.4 < $body_lum ? '#000000' : '#FFFFFF', 'gray-darker' => 0.4 < $body_lum ? 'darken(' . $body_bg . ', 13.5%)' : 'lighten(' . $body_bg . ', 13.5%)', 'gray-dark' => 0.4 < $body_lum ? 'darken(' . $body_bg . ', 20%)' : 'lighten(' . $body_bg . ', 20%)', 'gray' => 0.4 < $body_lum ? 'darken(' . $body_bg . ', 33.5%)' : 'lighten(' . $body_bg . ', 33.5%)', 'gray-light' => 0.4 < $body_lum ? 'darken(' . $body_bg . ', 60%)' : 'lighten(' . $body_bg . ', 60%)', 'gray-lighter' => 0.4 < $body_lum ? 'darken(' . $body_bg . ', 93.5%)' : 'lighten(' . $body_bg . ', 93.5%)', 'brand-primary' => '#' . $b_p_obj->getReadableContrastingColor(3)->toHex(), 'brand-success' => '#' . $color_success->getReadableContrastingColor(3)->toHex(), 'brand-info' => '#' . $color_info->getReadableContrastingColor(3)->toHex(), 'brand-warning' => '#' . $color_warning->getReadableContrastingColor(3)->toHex(), 'brand-danger' => '#' . $color_danger->getReadableContrastingColor(3)->toHex(), 'body-bg' => $body_bg, 'text-color' => '#' . $body_obj->getGrayscaleContrastingColor(10)->toHex(), 'link-color' => '#' . $b_p_obj->getReadableContrastingColor($body_obj, 2)->toHex(), 'link-hover-color' => 0.3 < $brand_primary_lum ? 'darken(@link-color, 15%)' : 'lighten(@link-color, 15%)', 'link-hover-decoration' => 'underline', 'font-family-sans-serif' => get_theme_mod('font_base_family', '"Helvetica Neue", Helvetica, Arial, sans-serif'), 'font-family-serif' => 'Georgia, "Times New Roman", Times, serif', 'font-family-monospace' => 'Menlo, Monaco, Consolas, "Courier New", monospace', 'font-family-base' => '@font-family-sans-serif', 'font-size-base' => $font_size_base, 'font-size-large' => 'ceil((@font-size-base * 1.25))', 'font-size-small' => 'ceil((@font-size-base * 0.85))', 'font-size-h1' => 'floor((@font-size-base * ' . get_theme_mod('font_headers_size', 1) * 2.6 . '))', 'font-size-h2' => 'floor((@font-size-base * ' . get_theme_mod('font_headers_size', 1) * 2.15 . '))', 'font-size-h3' => 'ceil((@font-size-base * ' . get_theme_mod('font_headers_size', 1) * 1.7 . '))', 'font-size-h4' => 'ceil((@font-size-base * ' . get_theme_mod('font_headers_size', 1) * 1.25 . '))', 'font-size-h5' => '@font-size-base', 'font-size-h6' => 'ceil((@font-size-base * ' . get_theme_mod('font_headers_size', 1) * 0.85 . '))', 'line-height-base' => get_theme_mod('font_base_height', 1.43), 'line-height-computed' => 'floor((@font-size-base * @line-height-base))', 'headings-font-family' => get_theme_mod('headers_font_family', '"Helvetica Neue", Helvetica, Arial, sans-serif'), 'headings-font-weight' => get_theme_mod('font_headers_weight', 500), 'headings-line-height' => get_theme_mod('font_headers_height', 1.1), 'headings-color' => 'inherit', 'icon-font-path' => '"' . MAERA_BS_SHELL_URL . '/assets/fonts/"', 'icon-font-name' => '"glyphicons-halflings-regular"', 'icon-font-svg-id' => '"glyphicons_halflingsregular"', 'padding-base-vertical' => round(get_theme_mod('padding_base', 6) * (6 / 6)) . 'px', 'padding-base-horizontal' => round(get_theme_mod('padding_base', 6) * (10 / 6)) . 'px', 'padding-large-vertical' => round(get_theme_mod('padding_base', 6) * (10 / 6)) . 'px', 'padding-large-horizontal' => round(get_theme_mod('padding_base', 6) * (16 / 6)) . 'px', 'padding-small-vertical' => round(get_theme_mod('padding_base', 6) * (5 / 6)) . 'px', 'padding-small-horizontal' => round(get_theme_mod('padding_base', 6) * (10 / 6)) . 'px', 'padding-xs-vertical' => round(get_theme_mod('padding_base', 6) * (1 / 6)) . 'px', 'padding-xs-horizontal' => round(get_theme_mod('padding_base', 6) * (5 / 6)) . 'px', 'line-height-large' => '1.33', 'line-height-small' => '1.5', 'border-radius-base' => round(get_theme_mod('border_radius', 4) * (4 / 4)) . 'px', 'border-radius-large' => round(get_theme_mod('border_radius', 4) * (6 / 4)) . 'px', 'border-radius-small' => round(get_theme_mod('border_radius', 4) * (3 / 4)) . 'px', 'component-active-color' => '@body-bg', 'component-active-bg' => '@brand-primary', 'caret-width-base' => '4px', 'caret-width-large' => '5px', 'table-cell-padding' => round(get_theme_mod('padding_base', 6) * (8 / 6)) . 'px', 'table-condensed-cell-padding' => round(get_theme_mod('padding_base', 6) * (5 / 6)) . 'px', 'table-bg' => 'transparent', 'table-bg-accent' => 0.3 < $body_lum ? 'darken(@body-bg, 2.5%)' : 'lighten(@body-bg, 2.5%)', 'table-bg-hover' => 0.3 < $body_lum ? 'darken(@body-bg, 4%)' : 'lighten(@body-bg, 4%)', 'table-bg-active' => '@table-bg-hover', 'table-border-color' => 0.3 < $body_lum ? 'darken(@body-bg, 13.35%)' : 'lighten(@body-bg, 13.35%)', 'btn-font-weight' => 'normal', 'btn-default-color' => '@text-color', 'btn-default-bg' => '@body-bg', 'btn-default-border' => 0.6 < $body_lum ? 'darken(@btn-primary-bg, 5%)' : 'lighten(@btn-primary-bg, 5%)', 'btn-primary-color' => '@body-bg', 'btn-primary-bg' => '@brand-primary', 'btn-primary-border' => 0.6 < $brand_primary_lum ? 'darken(@btn-primary-bg, 5%)' : 'lighten(@btn-primary-bg, 5%)', 'btn-success-color' => '@body-bg', 'btn-success-bg' => '@brand-success', 'btn-success-border' => 0.6 < $brand_success_lum ? 'darken(@btn-success-bg, 5%)' : 'lighten(@btn-success-bg, 5%)', 'btn-info-color' => '@body-bg', 'btn-info-bg' => '@brand-info', 'btn-info-border' => 0.6 < $brand_info_lum ? 'darken(@btn-info-bg, 5%)' : 'lighten(@btn-info-bg, 5%)', 'btn-warning-color' => '@body-bg', 'btn-warning-bg' => '@brand-warning', 'btn-warning-border' => 0.6 < $brand_warning_lum ? 'darken(@btn-warning-bg, 5%)' : 'lighten(@btn-warning-bg, 5%)', 'btn-danger-color' => '@body-bg', 'btn-danger-bg' => '@brand-danger', 'btn-danger-border' => 0.6 < $brand_danger_lum ? 'darken(@btn-danger-bg, 5%)' : 'lighten(@btn-danger-bg, 5%)', 'btn-link-disabled-color' => '@gray-light', 'input-bg' => '@body-bg', 'input-bg-disabled' => '@gray-lighter', 'input-color' => '@gray-dark', 'input-border' => 0.3 < $body_lum ? 'darken(@body-bg, 20%)' : 'lighten(@body-bg, 20%)', 'input-border-radius' => '@border-radius-base', 'input-border-radius-large' => 'border-radius-large', 'input-border-radius-small' => 'border-radius-small', 'input-border-focus' => 0.6 < $brand_primary_lum ? 'lighten(@brand-primary, 10%)' : 'darken(@brand-primary, 10%)', 'input-color-placeholder' => '@gray-light', 'input-height-base' => '(@line-height-computed + (@padding-base-vertical * 2) + 2)', 'input-height-large' => '(ceil(@font-size-large * @line-height-large) + (@padding-large-vertical * 2) + 2)', 'input-height-small' => '(floor(@font-size-small * @line-height-small) + (@padding-small-vertical * 2) + 2)', 'legend-color' => '@gray-dark', 'legend-border-color' => 0.3 < $body_lum ? 'darken(@body-bg, 10.2%)' : 'lighten(@body-bg, 10.2%)', 'input-group-addon-bg' => '@gray-lighter', 'input-group-addon-border-color' => '@input-border', 'cursor-disabled' => 'not-allowed', 'dropdown-bg' => '@body-bg', 'dropdown-border' => 'rgba(0,0,0,.15)', 'dropdown-fallback-border' => 0.3 < $body_lum ? 'darken(@body-bg, 20%)' : 'lighten(@body-bg, 20%)', 'dropdown-divider-bg' => 0.3 < $body_lum ? 'darken(@body-bg, 10.2%)' : 'lighten(@body-bg, 10.2%)', 'dropdown-link-color' => '@navbar-default-color', 'dropdown-link-hover-color' => '#' . $nav_col_obj->getGrayscaleContrastingColor(11)->toHex(), 'dropdown-link-hover-bg' => 0.3 < $body_lum ? 'darken(@body-bg, 4%)' : 'lighten(@body-bg, 4%)', 'dropdown-link-active-color' => '@component-active-color', 'dropdown-link-active-bg' => '@component-active-bg', 'dropdown-link-disabled-color' => '@gray-light', 'dropdown-header-color' => '@gray-light', 'dropdown-caret-color' => '@gray-darker', 'zindex-navbar' => '1000', 'zindex-dropdown' => '1000', 'zindex-popover' => '1060', 'zindex-tooltip' => '1070', 'zindex-navbar-fixed' => '1030', 'zindex-modal' => '1040', 'screen-xs' => '480px', 'screen-xs-min' => '@screen-xs', 'screen-phone' => '@screen-xs-min', 'screen-sm' => $screen_sm . 'px', 'screen-sm-min' => '@screen-sm', 'screen-tablet' => '@screen-sm-min', 'screen-md' => $screen_md . 'px', 'screen-md-min' => '@screen-md', 'screen-desktop' => '@screen-md-min', 'screen-lg' => $screen_lg . 'px', 'screen-lg-min' => '@screen-lg', 'screen-lg-desktop' => '@screen-lg-min', 'screen-xs-max' => '(@screen-sm-min - 1)', 'screen-sm-max' => '(@screen-md-min - 1)', 'screen-md-max' => '(@screen-lg-min - 1)', 'grid-columns' => '12', 'grid-gutter-width' => $gutter . 'px', 'grid-float-breakpoint' => $grid_float_breakpoint, 'grid-float-breakpoint-max' => '(@grid-float-breakpoint - 1)', 'container-tablet' => $screen_sm - $gutter / 2 . 'px', 'container-sm' => '@container-tablet', 'container-desktop' => $screen_md - $gutter / 2 . 'px', 'container-md' => '@container-desktop', 'container-large-desktop' => $screen_lg - $gutter . 'px', 'container-lg' => '@container-large-desktop', 'navbar-height' => filter_var(get_theme_mod('navbar_height', 50), FILTER_SANITIZE_NUMBER_INT) . 'px', 'navbar-margin-bottom' => '@line-height-computed', 'navbar-border-radius' => '@border-radius-base', 'navbar-padding-horizontal' => 'floor((@grid-gutter-width / 2))', 'navbar-padding-vertical' => '((@navbar-height - @line-height-computed) / 2)', 'navbar-collapse-max-height' => '340px', 'navbar-default-color' => '#' . $nav_col_obj->getGrayscaleContrastingColor(7)->toHex(), 'navbar-default-bg' => '#' . $nav_col_obj->toHex(), 'navbar-default-border' => 0.3 > $nav_col_obj->toLuminosity() ? 'lighten(@navbar-default-bg, 6.5%)' : 'darken(@navbar-default-bg, 6.5%)', 'navbar-default-link-color' => '@navbar-default-color', 'navbar-default-link-hover-color' => '#' . $nav_col_obj->getGrayscaleContrastingColor(11)->toHex(), 'navbar-default-link-hover-bg' => 'transparent', 'navbar-default-link-active-color' => 'mix(@navbar-default-color, @navbar-default-link-hover-color, 50%)', 'navbar-default-link-active-bg' => 0.6 > $nav_col_obj->toLuminosity() ? 'darken(@navbar-default-bg, 6.5%)' : 'lighten(@navbar-default-bg, 6.5%)', 'navbar-default-link-disabled-color' => 0.6 > $nav_col_obj->toLuminosity() ? 'darken(@navbar-default-bg, 6.5%)' : 'lighten(@navbar-default-bg, 6.5%)', 'navbar-default-link-disabled-bg' => 'transparent', 'navbar-default-brand-color' => '@navbar-default-link-color', 'navbar-default-brand-hover-color' => 'darken(@navbar-default-brand-color, 10%)', 'navbar-default-brand-hover-bg' => 'transparent', 'navbar-default-toggle-hover-bg' => 0.3 > $nav_col_obj->toLuminosity() ? 'lighten(@navbar-default-bg, 6.5%)' : 'darken(@navbar-default-bg, 6.5%)', 'navbar-default-toggle-icon-bar-bg' => '#' . $nav_col_obj->getGrayscaleContrastingColor(7)->toHex(), 'navbar-default-toggle-border-color' => '@navbar-default-toggle-hover-bg', 'navbar-inverse-color' => 'lighten(@gray-light, 15%)', 'navbar-inverse-bg' => '#222', 'navbar-inverse-border' => 'darken(@navbar-inverse-bg, 10%)', 'navbar-inverse-link-color' => 'lighten(@gray-light, 15%)', 'navbar-inverse-link-hover-color' => '@body-bg', 'navbar-inverse-link-hover-bg' => 'transparent', 'navbar-inverse-link-active-color' => '@navbar-inverse-link-hover-color', 'navbar-inverse-link-active-bg' => 'darken(@navbar-inverse-bg, 10%)', 'navbar-inverse-link-disabled-color' => '#444', 'navbar-inverse-link-disabled-bg' => 'transparent', 'navbar-inverse-brand-color' => '@navbar-inverse-link-color', 'navbar-inverse-brand-hover-color' => '@body-bg', 'navbar-inverse-brand-hover-bg' => 'transparent', 'navbar-inverse-toggle-hover-bg' => '#333', 'navbar-inverse-toggle-icon-bar-bg' => '@body-bg', 'navbar-inverse-toggle-border-color' => '#333', 'nav-link-padding' => round(get_theme_mod('padding_base', 6) * (10 / 6)) . 'px ' . round(get_theme_mod('padding_base', 6) * (15 / 6)) . 'px', 'nav-link-hover-bg' => '@gray-lighter', 'nav-disabled-link-color' => '@gray-light', 'nav-disabled-link-hover-color' => '@gray-light', 'nav-tabs-border-color' => 0.3 < $body_lum ? 'darken(@body-bg, 13.35%)' : 'lighten(@body-bg, 13.35%)', 'nav-tabs-link-hover-border-color' => '@gray-lighter', 'nav-tabs-active-link-hover-bg' => '@body-bg', 'nav-tabs-active-link-hover-color' => '@gray', 'nav-tabs-active-link-hover-border-color' => 0.3 < $body_lum ? 'darken(@body-bg, 13.35%)' : 'lighten(@body-bg, 13.35%)', 'nav-tabs-justified-link-border-color' => 0.3 < $body_lum ? 'darken(@body-bg, 13.35%)' : 'lighten(@body-bg, 13.35%)', 'nav-tabs-justified-active-link-border-color' => '@body-bg', 'nav-pills-border-radius' => '@border-radius-base', 'nav-pills-active-link-hover-bg' => '@component-active-bg', 'nav-pills-active-link-hover-color' => '@component-active-color', 'pagination-color' => '@link-color', 'pagination-bg' => '@body-bg', 'pagination-border' => 0.3 < $body_lum ? 'darken(@body-bg, 13.35%)' : 'lighten(@body-bg, 13.35%)', 'pagination-hover-color' => '@link-hover-color', 'pagination-hover-bg' => '@gray-lighter', 'pagination-hover-border' => 0.3 < $body_lum ? 'darken(@body-bg, 13.35%)' : 'lighten(@body-bg, 13.35%)', 'pagination-active-color' => '@body-bg', 'pagination-active-bg' => '@brand-primary', 'pagination-active-border' => '@brand-primary', 'pagination-disabled-color' => '@gray-light', 'pagination-disabled-bg' => '@body-bg', 'pagination-disabled-border' => 0.3 < $body_lum ? 'darken(@body-bg, 13.35%)' : 'lighten(@body-bg, 13.35%)', 'pager-bg' => '@pagination-bg', 'pager-border' => '@pagination-border', 'pager-border-radius' => round(get_theme_mod('border_radius', 4) * (15 / 4)) . 'px', 'pager-hover-bg' => '@pagination-hover-bg', 'pager-active-bg' => '@pagination-active-bg', 'pager-active-color' => '@pagination-active-color', 'pager-disabled-color' => '@pagination-disabled-color', 'jumbotron-padding' => round(get_theme_mod('padding_base', 6) * (30 / 6)) . 'px', 'jumbotron-color' => 'inherit', 'jumbotron-bg' => '#' . $jumbotron_obj->toHex(), 'jumbotron-heading-color' => 'inherit', 'jumbotron-font-size' => get_theme_mod('font_jumbotron_size', 20), 'state-success-text' => '@brand-success', 'state-success-bg' => 'mix(@body-bg, @brand-success, 70%)', 'state-success-border' => 'darken(spin(@state-success-bg, -10), 5%)', 'state-info-text' => '@brand-info', 'state-info-bg' => 'mix(@body-bg, @brand-info, 70%)', 'state-info-border' => 'darken(spin(@state-info-bg, -10), 7%)', 'state-warning-text' => '@brand-warning', 'state-warning-bg' => 'mix(@body-bg, @brand-warning, 70%)', 'state-warning-border' => 'darken(spin(@state-warning-bg, -10), 5%)', 'state-danger-text' => '@brand-danger', 'state-danger-bg' => 'mix(@body-bg, @brand-danger, 70%)', 'state-danger-border' => 'darken(spin(@state-danger-bg, -10), 5%)', 'tooltip-max-width' => '200px', 'tooltip-color' => '@body-bg', 'tooltip-bg' => 'darken(@gray-darker, 15%)', 'tooltip-opacity' => '.9', 'tooltip-arrow-width' => '5px', 'tooltip-arrow-color' => '@tooltip-bg', 'popover-bg' => '@body-bg', 'popover-max-width' => '276px', 'popover-border-color' => 'rgba(0,0,0,.2)', 'popover-fallback-border-color' => 0.3 < $body_lum ? 'darken(@body-bg, 20%)' : 'lighten(@body-bg, 20%)', 'popover-title-bg' => 'darken(@popover-bg, 3%)', 'popover-arrow-width' => '10px', 'popover-arrow-color' => '@popover-bg', 'popover-arrow-outer-width' => '(@popover-arrow-width + 1)', 'popover-arrow-outer-color' => 'fadein(@popover-border-color, 5%)', 'popover-arrow-outer-fallback-color' => 'darken(@popover-fallback-border-color, 20%)', 'label-default-bg' => '@gray-light', 'label-primary-bg' => '@brand-primary', 'label-success-bg' => '@brand-success', 'label-info-bg' => '@brand-info', 'label-warning-bg' => '@brand-warning', 'label-danger-bg' => '@brand-danger', 'label-color' => '@body-bg', 'label-link-hover-color' => '@body-bg', 'modal-inner-padding' => round(get_theme_mod('padding_base', 6) * (15 / 6)) . 'px', 'modal-title-padding' => round(get_theme_mod('padding_base', 6) * (15 / 6)) . 'px', 'modal-title-line-height' => '@line-height-base', 'modal-content-bg' => '@body-bg', 'modal-content-border-color' => 'rgba(0,0,0,.2)', 'modal-content-fallback-border-color' => '#999', 'modal-backdrop-bg' => '#000', 'modal-backdrop-opacity' => '.5', 'modal-header-border-color' => 0.3 < $body_lum ? 'darken(@body-bg, 10.2%)' : 'lighten(@body-bg, 10.2%)', 'modal-footer-border-color' => '@modal-header-border-color', 'modal-lg' => round($screen_md - 3 * $gutter) . 'px', 'modal-md' => round($screen_sm - 3 * $gutter) . 'px', 'modal-sm' => round($screen_xs - 3 * $gutter) . 'px', 'alert-padding' => round(get_theme_mod('padding_base', 6) * (15 / 6)) . 'px', 'alert-border-radius' => '@border-radius-base', 'alert-link-font-weight' => 'bold', 'alert-success-bg' => '@state-success-bg', 'alert-success-text' => '@state-success-text', 'alert-success-border' => '@state-success-border', 'alert-info-bg' => '@state-info-bg', 'alert-info-text' => '@state-info-text', 'alert-info-border' => '@state-info-border', 'alert-warning-bg' => '@state-warning-bg', 'alert-warning-text' => '@state-warning-text', 'alert-warning-border' => '@state-warning-border', 'alert-danger-bg' => '@state-danger-bg', 'alert-danger-text' => '@state-danger-text', 'alert-danger-border' => '@state-danger-border', 'progress-bg' => 0.3 < $body_lum ? 'darken(@body-bg, 4%)' : 'lighten(@body-bg, 4%)', 'progress-bar-color' => '@body-bg', 'progress-border-radius' => 'border-radius-base', 'progress-bar-bg' => '@brand-primary', 'progress-bar-success-bg' => '@brand-success', 'progress-bar-warning-bg' => '@brand-warning', 'progress-bar-danger-bg' => '@brand-danger', 'progress-bar-info-bg' => '@brand-info', 'list-group-bg' => '@body-bg', 'list-group-border' => 0.3 < $body_lum ? 'darken(@body-bg, 13.35%)' : 'lighten(@body-bg, 13.35%)', 'list-group-border-radius' => '@border-radius-base', 'list-group-hover-bg' => 0.3 < $body_lum ? 'darken(@body-bg, 4%)' : 'lighten(@body-bg, 4%)', 'list-group-active-color' => '@component-active-color', 'list-group-active-bg' => '@component-active-bg', 'list-group-active-border' => '@list-group-active-bg', 'list-group-active-text-color' => 'lighten(@list-group-active-bg, 40%)', 'list-group-disabled-color' => 'gray-light', 'list-group-disabled-bg' => 'gray-lighter', 'list-group-disabled-text-color' => 'list-group-disabled-color', 'list-group-link-color' => '@gray', 'list-group-link-hover-color' => '@list-group-link-color', 'list-group-link-heading-color' => '@gray-dark', 'panel-bg' => '@body-bg', 'panel-body-padding' => round(get_theme_mod('padding_base', 6) * (15 / 6)) . 'px', 'panel-heading-padding' => round(get_theme_mod('padding_base', 6) * (10 / 6)) . 'px ' . round(get_theme_mod('padding_base', 6) * (15 / 6)) . 'px', 'panel-footer-padding' => '@panel-heading-padding', 'panel-border-radius' => '@border-radius-base', 'panel-inner-border' => 0.3 < $body_lum ? 'darken(@body-bg, 13.35%)' : 'lighten(@body-bg, 13.35%)', 'panel-footer-bg' => 0.3 < $body_lum ? 'darken(@body-bg, 4%)' : 'lighten(@body-bg, 4%)', 'panel-default-text' => '@gray-dark', 'panel-default-border' => 0.3 < $body_lum ? 'darken(@body-bg, 13.35%)' : 'lighten(@body-bg, 13.35%)', 'panel-default-heading-bg' => 0.3 < $body_lum ? 'darken(@body-bg, 4%)' : 'lighten(@body-bg, 4%)', 'panel-primary-text' => '@body-bg', 'panel-primary-border' => '@brand-primary', 'panel-primary-heading-bg' => '@brand-primary', 'panel-success-text' => '@state-success-text', 'panel-success-border' => '@state-success-border', 'panel-success-heading-bg' => '@state-success-bg', 'panel-info-text' => '@state-info-text', 'panel-info-border' => '@state-info-border', 'panel-info-heading-bg' => '@state-info-bg', 'panel-warning-text' => '@state-warning-text', 'panel-warning-border' => '@state-warning-border', 'panel-warning-heading-bg' => '@state-warning-bg', 'panel-danger-text' => '@state-danger-text', 'panel-danger-border' => '@state-danger-border', 'panel-danger-heading-bg' => '@state-danger-bg', 'thumbnail-padding' => round(get_theme_mod('padding_base', 6) * (4 / 6)) . 'px', 'thumbnail-bg' => '@body-bg', 'thumbnail-border' => 0.3 < $body_lum ? 'darken(@body-bg, 13.35%)' : 'lighten(@body-bg, 13.35%)', 'thumbnail-border-radius' => '@border-radius-base', 'thumbnail-caption-color' => '@text-color', 'thumbnail-caption-padding' => round(get_theme_mod('padding_base', 6) * (9 / 6)) . 'px', 'well-bg' => 0.3 < $body_lum ? 'darken(@body-bg, 4%)' : 'lighten(@body-bg, 4%)', 'well-border' => 'darken(@well-bg, 7%)', 'badge-color' => '@body-bg', 'badge-link-hover-color' => '@body-bg', 'badge-bg' => '@gray-light', 'badge-active-color' => '@link-color', 'badge-active-bg' => '@body-bg', 'badge-font-weight' => 'bold', 'badge-line-height' => '1', 'badge-border-radius' => round(get_theme_mod('border_radius', 4) * (10 / 4)) . 'px', 'breadcrumb-padding-vertical' => round(get_theme_mod('padding_base', 6) * (8 / 6)) . 'px', 'breadcrumb-padding-horizontal' => round(get_theme_mod('padding_base', 6) * (15 / 6)) . 'px', 'breadcrumb-bg' => 0.3 < $body_lum ? 'darken(@body-bg, 4%)' : 'lighten(@body-bg, 4%)', 'breadcrumb-color' => 0.3 < $body_lum ? 'darken(@body-bg, 20%)' : 'lighten(@body-bg, 20%)', 'breadcrumb-active-color' => '@gray-light', 'breadcrumb-separator' => '"/"', 'carousel-text-shadow' => '0 1px 2px rgba(0,0,0,.6)', 'carousel-control-color' => '@body-bg', 'carousel-control-width' => '15%', 'carousel-control-opacity' => '.5', 'carousel-control-font-size' => '20px', 'carousel-indicator-active-bg' => '@body-bg', 'carousel-indicator-border-color' => '@body-bg', 'carousel-caption-color' => '@body-bg', 'close-font-weight' => 'bold', 'close-color' => '#000', 'close-text-shadow' => '0 1px 0 #fff', 'code-color' => '#c7254e', 'code-bg' => '#f9f2f4', 'kbd-color' => '@body-bg', 'kbd-bg' => '#333', 'pre-bg' => 0.3 < $body_lum ? 'darken(@body-bg, 4%)' : 'lighten(@body-bg, 4%)', 'pre-color' => '@gray-dark', 'pre-border-color' => 0.3 < $body_lum ? 'darken(@body-bg, 20%)' : 'lighten(@body-bg, 20%)', 'pre-scrollable-max-height' => '340px', 'component-offset-horizontal' => '180px', 'text-muted' => '@gray-light', 'abbr-border-color' => '@gray-light', 'headings-small-color' => '@gray-light', 'blockquote-small-color' => '@gray-light', 'blockquote-font-size' => '(@font-size-base * 1.25)', 'blockquote-border-color' => '@gray-lighter', 'page-header-border-color' => '@gray-lighter', 'hr-border' => '@gray-lighter', 'dl-horizontal-offset' => '@component-offset-horizontal'); return $variables; }
/** * Returns an array properly formatted for use by the Kirki_Palette control. * * @param $palettes_nr int the number of palettes we want to get * @return array */ public static function get_palettes($palettes_nr = 5) { $palettes = self::parse(); $palettes = array_slice($palettes, 0, $palettes_nr); $i = 0; foreach ($palettes as $palette) { $palettes[$i] = array(); foreach ($palette as $key => $value) { $palettes[$i][$key] = Kirki_Color::sanitize_hex($value); } $i++; } return $palettes; }
public function test() { $this->assertEquals(kirki_get_option(), Kirki::get_option()); $this->assertEquals(kirki_sanitize_hex('#ffffff'), Kirki_Color::sanitize_hex('#ffffff')); $this->assertEquals(kirki_get_rgb('#ffffff'), Kirki_Color::get_rgb('#ffffff')); $this->assertEquals(kirki_get_rgba('#ffffff'), Kirki_Color::get_rgba('#ffffff')); $this->assertEquals(kirki_get_brightness('#ffffff'), Kirki_Color::get_brightness('#ffffff')); $font_registry = Kirki_Toolkit::fonts(); $this->assertEquals(Kirki_Fonts::get_all_fonts(), $font_registry->get_all_fonts()); $this->assertEquals(Kirki_Fonts::get_font_choices(), $font_registry->get_font_choices()); $this->assertEquals(Kirki_Fonts::is_google_font('foo'), $font_registry->is_google_font('foo')); $this->assertEquals(Kirki_Fonts::get_google_font_uri(array('foo')), $font_registry->get_google_font_uri(array('foo'))); $this->assertEquals(Kirki_Fonts::get_google_font_subsets(), $font_registry->get_google_font_subsets()); $this->assertEquals(Kirki_Fonts::choose_google_font_variants('Roboto'), $font_registry->choose_google_font_variants('Roboto')); $this->assertEquals(Kirki_Fonts::get_standard_fonts(), $font_registry->get_standard_fonts()); $this->assertEquals(Kirki_Fonts::get_font_stack('foo'), $font_registry->get_font_stack('foo')); $this->assertEquals(Kirki_Fonts::sanitize_font_choice('foo'), $font_registry->sanitize_font_choice('foo')); $this->assertEquals(Kirki_Fonts::get_google_fonts(), $font_registry->get_google_fonts()); }
public static function setSection($config_id, $args = array()) { if (!isset($args['fields']) || !isset($args['subsection']) || isset($args['subsection']) && !$args['subsection']) { // This is a panel Kirki::$panels[] = array('id' => isset($args['id']) ? sanitize_key($args['id']) : substr(str_shuffle('abcdefghijklmnopqrstuvwxyz-_'), 0, 7), 'title' => isset($args['title']) ? $args['title'] : '', 'priority' => isset($args['priority']) ? $args['priority'] : 10, 'description' => isset($args['desc']) ? $args['desc'] : ''); } else { // This is a section // Get the section ID if (isset($args['subsection']) && $args['subsection']) { $panel = end(array_values(Kirki::$panels)); $panel_id = $panel['id']; } Kirki::$sections[] = array('id' => isset($args['id']) ? sanitize_key($args['id']) : substr(str_shuffle("abcdefghijklmnopqrstuvwxyz-_"), 0, 7), 'title' => $args['title'], 'priority' => isset($args['priority']) ? $args['priority'] : 10, 'panel' => isset($panel_id) ? $panel_id : '', 'description' => isset($args['desc']) ? $args['desc'] : ''); foreach ($args['fields'] as $field) { $field['section'] = isset($args['id']) ? sanitize_key($args['id']) : substr(str_shuffle("abcdefghijklmnopqrstuvwxyz-_"), 0, 7); $field['settings'] = $field['id']; $field['help'] = isset($field['desc']) ? $field['desc'] : ''; $field['description'] = isset($field['subtitle']) ? $field['subtitle'] : ''; $field['choices'] = isset($field['options']) ? $field['options'] : ''; $field['label'] = isset($field['title']) ? $field['title'] : ''; switch ($field['type']) { case 'ace_editor': $field['type'] = 'textarea'; break; case 'button_set': $field['type'] = 'radio-buttonset'; break; case 'checkbox': if (isset($field['options']) && is_array($field['options'])) { $field['type'] = 'multicheck'; } case 'color_rgba': $field['type'] = 'color-alpha'; if (isset($field['default']) && is_array($field['default'])) { $field['default']['color'] = isset($field['default']['color']) ? Kirki_Color::sanitize_hex($field['default']['color'], true) : '#ffffff'; $field['default']['alpha'] = isset($field['default']['alpha']) ? $field['default']['alpha'] : '1'; $field['default'] = Kirki_Color::get_rgba($field['default']['color'], $field['default']['alpha']); } break; case 'image_select': $field['type'] = 'radio-image'; break; case 'info': $fiel['label'] = ''; $field['help'] = ''; $field['type'] = 'custom'; $background_color = '#fcf8e3'; $border_color = '#faebcc'; $text_color = '#8a6d3b'; if (isset($field['style'])) { if ('success' == $field['style']) { $background_color = '#dff0d8'; $border_color = '#d6e9c6'; $text_color = '#3c763d'; } elseif ('critical' == $field['style']) { $background_color = '#f2dede'; $border_color = '#ebccd1'; $text_color = '#a94442'; } } $field['default'] = '<div style="padding: 10px;background:' . $background_color . ';border-radius:4px;border:1px solid ' . $border_color . ';color:' . $text_color . ';">'; $field['default'] .= isset($field['title']) ? '<h4>' . $field['title'] . '</h4>' : ''; $field['default'] .= isset($field['desc']) ? $field['desc'] : ''; $field['default'] .= '</div>'; break; case 'palette': $field['choices'] = $field['palettes']; break; case 'raw': $field['default'] = $field['content']; break; case 'select': if (is_array($field['choices'])) { foreach ($field['choices'] as $key => $value) { if (is_array($value)) { foreach ($value as $child_key => $child_value) { $field['choices'][$child_key] = $child_value; } unset($field['choices'][$key]); } } } break; case 'slider': $field['choices'] = array('min' => $field['min'], 'max' => $field['max'], 'step' => $field['step']); break; case 'spinner': $field['type'] = 'number'; break; case 'background': case 'border': case 'color_gradient': case 'date': case 'dimensions': case 'divide': case 'gallery': case 'import_export': case 'link_color': case 'media': case 'multi_text': case 'password': case 'section': case 'select_image': case 'sortable': case 'sorter': case 'spacing': case 'spinner': case 'switch': case 'typography': case 'slides': // TODO break; } Kirki::add_field($config_id, $field); } } }
/** * Build the background fields. * Takes a single field with type = background and explodes it to multiple controls. * * @param array * @return null|array */ public static function explode($field) { $i18n = Kirki_Toolkit::i18n(); $choices = self::background_choices(); // Early exit if this is not a background field. if ('background' != $field['type']) { return; } // Sanitize field $field = Kirki_Field_Sanitize::sanitize_field($field); // No need to proceed any further if no defaults have been set. // We build the array of fields based on what default values have been defined. if (!isset($field['default']) || !is_array($field['default'])) { return; } $fields = array(); $i = 0; foreach ($field['default'] as $key => $value) { // No need to process the opacity, it is factored in the color control. if ('opacity' == $key) { continue; } $key = esc_attr($key); $setting = $key; $help = $field['help']; $description = isset($i18n['background-' . $key]) ? $i18n['background-' . $key] : ''; $output_property = 'background-' . $key; $label = 0 === $i ? $field['label'] : ''; $type = 'select'; $sanitize_callback = 'esc_attr'; switch ($key) { case 'color': /** * Use 'color-alpha' instead of 'color' if default is an rgba value * or if 'opacity' is set. */ $type = false !== strpos($field['default']['color'], 'rgba') ? 'color-alpha' : 'color'; $type = isset($field['default']['opacity']) ? 'color-alpha' : $type; if (isset($field['default']['opacity']) && false === strpos($value, 'rgb')) { $value = Kirki_Color::get_rgba($value, $field['default']['opacity']); } $sanitize_callback = array('Kirki_Sanitize_Values', 'color'); break; case 'image': $type = 'image'; $sanitize_callback = 'esc_url_raw'; break; case 'attach': /** * Small hack so that background attachments properly work. */ $output_property = 'background-attachment'; $description = $i18n['background-attachment']; break; default: $help = ''; break; } /** * If we're using options & option_name is set, then we need to modify the setting. */ if (isset($field['option_type']) && 'option' == $field['option_type'] && isset($field['option_name']) && !empty($field['option_name'])) { $property_setting = str_replace(']', '', str_replace($field['option_name'] . '[', '', $field['settings'])); $property_setting = esc_attr($field['option_name']) . '[' . esc_attr($property_setting) . '_' . $setting . ']'; } else { $property_setting = esc_attr($field['settings']) . '_' . $setting; } /** * Build the field. * We're merging with the original field here, so any extra properties are inherited. */ $fields[$property_setting] = array_merge($field, array('type' => $type, 'label' => $label, 'settings' => $property_setting, 'help' => $help, 'section' => $field['section'], 'priority' => $field['priority'], 'required' => $field['required'], 'description' => $description, 'default' => $value, 'id' => Kirki_Field_Sanitize::sanitize_id(array('settings' => $field['settings'] . '_' . $setting)), 'choices' => isset($choices[$key]) ? $choices[$key] : array(), 'output' => '' != $field['output'] ? array(array('element' => $field['output'], 'property' => $output_property)) : '', 'sanitize_callback' => isset($sanitize_callback) ? $sanitize_callback : Kirki_Field_Sanitize::fallback_callback($type))); $i++; } return $fields; }
/** * Sanitize RGBA colors * * @since 0.8.5 */ function kirki_sanitize_rgba($value) { // If empty or an array return transparent if (empty($value) || is_array($value)) { return 'rgba(0,0,0,0)'; } // If string does not start with 'rgba', then treat as hex // sanitize the hex color and finally convert hex to rgba if (false === strpos($value, 'rgba')) { return Kirki_Color::get_rgba(Kirki_Color::sanitize_hex($value)); } // By now we know the string is formatted as an rgba color so we need to further sanitize it. $value = str_replace(' ', '', $value); sscanf($value, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha); return 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $alpha . ')'; }
public function test_lumosity_difference() { $this->assertEquals('1', Kirki_Color::lumosity_difference('fff', '#ffffff')); $this->assertEquals('21', Kirki_Color::lumosity_difference('fff', '000')); $this->assertEquals('21', Kirki_Color::lumosity_difference('#000000', '#ffffff')); $this->assertEquals('5.23', Kirki_Color::lumosity_difference('#f2f2f2', '#c00')); $this->assertEquals('1.12', Kirki_Color::lumosity_difference('#f2f2f2', '#ffffff')); }
/** * Calculate some extra CSS styles and attach them to the main stylesheet */ public function extra_styles() { $css = ''; $color = get_theme_mod('accent_color', '#a46497'); $color = false !== strpos($color, 'rgba') ? Kirki_Color::rgba2hex($color) : $color; if (127 < Kirki_Color::get_brightness($color)) { $text_color = '#515151'; $hover_color = Kirki_Color::adjust_brightness($color, 10); } else { $text_color = '#ffffff'; $hover_color = Kirki_Color::adjust_brightness($color, -10); } /** * Header Styles */ $color = get_theme_mod('header_background_color', '#111111'); $color = false !== strpos($color, 'rgb') ? Kirki_Color::rgba2hex($color) : $color; $header_textcolor = 127 < Kirki_Color::get_brightness($color) ? '#222222' : '#ffffff'; $header_border_color = 127 < Kirki_Color::get_brightness($color) ? 'rgba(0,0,0,.1)' : 'rgba(255,255,255,.08)'; $css .= '.horizontal-menu a, .horizontal-menu a:visited, #header-wrapper .dashicons, #header-wrapper .breadcrumbs .woocommerce-breadcrumb, #header-wrapper .breadcrumbs a, #header-wrapper .breadcrumbs .woocommerce-breadbrumb a, h1.site-title a, #header-wrapper .search-wrapper input { color:' . $header_textcolor . ';}'; $css .= '#ffffff' == $header_textcolor ? 'body .horizontal-menu a:hover{color: rgba(255,255,255,.75);}' : 'body .horizontal-menu a:hover{color: rgba(0,0,0,.75);}'; $css .= '#header-wrapper .sidebar-button svg { fill:' . $header_textcolor . ';}'; $css .= '.horizontal-menu{border-top-color:' . $header_border_color . ';}'; /** * Sidebar alignment */ $css .= 'l' == get_theme_mod('sidebar_position', 'l') ? '#content.site-content{flex-direction:row-reverse;}' : ''; /** * If we are not on a full-width layout, then add some extra CSS to fix grid spacing * depending on the sidebar's location (left/right) */ if (get_theme_mod('sidebar_width', 3)) { $css .= 'l' == get_theme_mod('sidebar_position', 'l') ? '#primary{margin-right:0;}' : '#secondary{margin-right:0;}'; } /** * Product Category background image. * This image is set as background on the product description area. */ if (get_theme_mod('product_cat_image_height')) { if (is_tax(array('product_cat', 'product_tag')) && get_query_var('paged') == 0) { global $wp_query; $term = $wp_query->get_queried_object(); $thumbnail_id = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true); $image = wp_get_attachment_url($thumbnail_id); if ($image) { $css .= '.woocommerce .term-description.has-term-image{background-image: url(' . $image . ');}'; } } } /** * OffCanvas menu. * Default is white color, so we'll only override this if needed. */ $color = get_theme_mod('offcanvas_menu_background_color', '#a46497'); $color = false !== strpos($color, 'rgba') ? Kirki_Color::rgba2hex($color) : $color; if (127 < Kirki_Color::get_brightness($color)) { $css .= '.left-offcanvas-menu ul li a, .left-offcanvas-menu .close{color:#222222;}'; } /** * OffCanvas sidebar */ $color = get_theme_mod('offcanvas_sidebar_background_color', '#a46497'); $color = false !== strpos($color, 'rgba') ? Kirki_Color::rgba2hex($color) : $color; if (127 < Kirki_Color::get_brightness($color)) { $offcanvas_sidebar_color = '#222222'; } else { $offcanvas_sidebar_color = '#ffffff'; } $css .= 'body .offcanvas-sidebar, body .offcanvas-sidebar a, body .offcanvas-sidebar a:visited, body .offcanvas-sidebar a:hover.offcanvas-sidebar .close{color:' . $offcanvas_sidebar_color . ';}'; /** * Button mods */ $css .= 'button, input[type="button"], input[type="reset"], input[type="submit"], .woocommerce #respond input#submit, .woocommerce a.button, .woocommerce button.button, .woocommerce input.button{font-weight:' . get_theme_mod('font_base_weight', 700) . ';}'; $css .= 'button, input[type="button"], input[type="reset"], input[type="submit"] {background-color:' . get_theme_mod('accent_color', '#a46497') . '; color:' . $text_color . '}'; $css .= 'button:hover, input[type="button"]:hover, input[type="reset"]:hover, input[type="submit"]:hover, button:active, input[type="button"]:active, input[type="reset"]:active, input[type="submit"]:active { background-color:' . $hover_color . ';}'; // Attach our custom styles to the main stylesheet using wp_add_inline_style // See http://codex.wordpress.org/Function_Reference/wp_add_inline_style for documentation wp_add_inline_style('ornea-styles', $css); }
/** * Sanitize colors. * Determine if the current value is a hex or an rgba color and call the appropriate method. * * @since 0.8.5 * @return string */ public static function color($value) { // Is this an rgba color or a hex? $mode = false === strpos($value, 'rgba') ? 'rgba' : 'hex'; if ('rgba' == $mode) { return Kirki_Color::sanitize_hex($value); } else { return self::rgba($value); } }
public static function order_by($palette = array(), $order = 'none') { $palette = empty($palette) ? array() : $palette; if ('none' == $order) { $palette = array(Kirki_Color::sanitize_hex($palette[0]), Kirki_Color::sanitize_hex($palette[1]), Kirki_Color::sanitize_hex($palette[2]), Kirki_Color::sanitize_hex($palette[3]), Kirki_Color::sanitize_hex($palette[4])); } elseif ('brightness' == $order) { // Get the ligtness of all the colors in our palette and arrange them according to it. $colors_array_0b = $palette; $brightest_0_key = Kirki_Color::brightest_color($colors_array_0b, 'key'); $brightest_0_val = Kirki_Color::brightest_color($colors_array_0b, 'value'); $colors_array_1b = kirki_array_delete($brightest_0_key, $colors_array_0b); $brightest_1_key = Kirki_Color::brightest_color($colors_array_1b, 'key'); $brightest_1_val = Kirki_Color::brightest_color($colors_array_1b, 'value'); $colors_array_2b = kirki_array_delete($brightest_1_key, $colors_array_1b); $brightest_2_key = Kirki_Color::brightest_color($colors_array_2b, 'key'); $brightest_2_val = Kirki_Color::brightest_color($colors_array_2b, 'value'); $colors_array_3b = kirki_array_delete($brightest_2_key, $colors_array_2b); $brightest_3_key = Kirki_Color::brightest_color($colors_array_3b, 'key'); $brightest_3_val = Kirki_Color::brightest_color($colors_array_3b, 'value'); $colors_array_4b = kirki_array_delete($brightest_3_key, $colors_array_3b); $brightest_4_key = Kirki_Color::brightest_color($colors_array_4b, 'key'); $brightest_4_val = Kirki_Color::brightest_color($colors_array_4b, 'value'); $palette = array(Kirki_Color::sanitize_hex($brightest_0_val), Kirki_Color::sanitize_hex($brightest_1_val), Kirki_Color::sanitize_hex($brightest_2_val), Kirki_Color::sanitize_hex($brightest_3_val), Kirki_Color::sanitize_hex($brightest_4_val)); } elseif ('saturation' == $order) { // Get the saturation of all the colors in our palette and arrange them according to it. $colors_array_0s = $palette; $most_saturated_0_key = Kirki_Color::most_saturated_color($colors_array_0s, 'key'); $most_saturated_0_val = Kirki_Color::most_saturated_color($colors_array_0s, 'value'); $colors_array_1s = kirki_array_delete($most_saturated_0_key, $colors_array_0s); $most_saturated_1_key = Kirki_Color::most_saturated_color($colors_array_1s, 'key'); $most_saturated_1_val = Kirki_Color::most_saturated_color($colors_array_1s, 'value'); $colors_array_2s = kirki_array_delete($most_saturated_1_key, $colors_array_1s); $most_saturated_2_key = Kirki_Color::most_saturated_color($colors_array_2s, 'key'); $most_saturated_2_val = Kirki_Color::most_saturated_color($colors_array_2s, 'value'); $colors_array_3s = kirki_array_delete($most_saturated_2_key, $colors_array_2s); $most_saturated_3_key = Kirki_Color::most_saturated_color($colors_array_3s, 'key'); $most_saturated_3_val = Kirki_Color::most_saturated_color($colors_array_3s, 'value'); $colors_array_4s = kirki_array_delete($most_saturated_3_key, $colors_array_3s); $most_saturated_3_key = Kirki_Color::most_saturated_color($colors_array_4s, 'key'); $most_saturated_4_val = Kirki_Color::most_saturated_color($colors_array_4s, 'value'); $palette = array(Kirki_Color::sanitize_hex($most_saturated_0_val), Kirki_Color::sanitize_hex($most_saturated_1_val), Kirki_Color::sanitize_hex($most_saturated_2_val), Kirki_Color::sanitize_hex($most_saturated_3_val), Kirki_Color::sanitize_hex($most_saturated_4_val)); } elseif ('intensity' == $order) { // Get the intensity of all the colors in our palette and arrange them according to it. $colors_array_0i = $palette; $most_intense_0_key = Kirki_Color::most_intense_color($colors_array_0i, 'key'); $most_intense_0_val = Kirki_Color::most_intense_color($colors_array_0i, 'value'); $colors_array_1i = kirki_array_delete($most_intense_0_key, $colors_array_0i); $most_intense_1_key = Kirki_Color::most_intense_color($colors_array_1i, 'key'); $most_intense_1_val = Kirki_Color::most_intense_color($colors_array_1i, 'value'); $colors_array_2i = kirki_array_delete($most_intense_1_key, $colors_array_1i); $most_intense_2_key = Kirki_Color::most_intense_color($colors_array_2i, 'key'); $most_intense_2_val = Kirki_Color::most_intense_color($colors_array_2i, 'value'); $colors_array_3i = kirki_array_delete($most_intense_2_key, $colors_array_2i); $most_intense_3_key = Kirki_Color::most_intense_color($colors_array_3i, 'key'); $most_intense_3_val = Kirki_Color::most_intense_color($colors_array_3i, 'value'); $colors_array_4i = kirki_array_delete($most_intense_3_key, $colors_array_3i); $most_intense_3_key = Kirki_Color::most_intense_color($colors_array_4i, 'key'); $most_intense_4_val = Kirki_Color::most_intense_color($colors_array_4i, 'value'); $palette = array(Kirki_Color::sanitize_hex($most_intense_0_val), Kirki_Color::sanitize_hex($most_intense_1_val), Kirki_Color::sanitize_hex($most_intense_2_val), Kirki_Color::sanitize_hex($most_intense_3_val), Kirki_Color::sanitize_hex($most_intense_4_val)); } elseif ('dullness' == $order) { // Get the lightness and "dullness" of all the colors in our palette and arrange them according to it. $colors_array_0d = $palette; $bright_dull_0_key = Kirki_Color::brightest_dull_color($colors_array_0d, 'key'); $bright_dull_0_val = Kirki_Color::brightest_dull_color($colors_array_0d, 'value'); $colors_array_1d = kirki_array_delete($bright_dull_0_key, $colors_array_0d); $bright_dull_1_key = Kirki_Color::brightest_dull_color($colors_array_1d, 'key'); $bright_dull_1_val = Kirki_Color::brightest_dull_color($colors_array_1d, 'value'); $colors_array_2d = kirki_array_delete($bright_dull_1_key, $colors_array_1d); $bright_dull_2_key = Kirki_Color::brightest_dull_color($colors_array_2d, 'key'); $bright_dull_2_val = Kirki_Color::brightest_dull_color($colors_array_2d, 'value'); $colors_array_3d = kirki_array_delete($bright_dull_2_key, $colors_array_2d); $bright_dull_3_key = Kirki_Color::brightest_dull_color($colors_array_3d, 'key'); $bright_dull_3_val = Kirki_Color::brightest_dull_color($colors_array_3d, 'value'); $colors_array_4d = kirki_array_delete($bright_dull_3_key, $colors_array_3d); $bright_dull_3_key = Kirki_Color::brightest_dull_color($colors_array_4d, 'key'); $bright_dull_4_val = Kirki_Color::brightest_dull_color($colors_array_4d, 'value'); $palette = array(Kirki_Color::sanitize_hex($bright_dull_0_val), Kirki_Color::sanitize_hex($bright_dull_1_val), Kirki_Color::sanitize_hex($bright_dull_2_val), Kirki_Color::sanitize_hex($bright_dull_3_val), Kirki_Color::sanitize_hex($bright_dull_4_val)); } return $palette; }
/** * Get the styles for a single field. */ public function setting_styles($field, $styles = '', $element = '', $property = '', $units = '', $prefix = '', $suffix = '', $callback = false) { $value = kirki_get_option($field['settings_raw']); $value = $callback ? call_user_func($callback, $value) : $value; $element = $prefix . $element; $units = $units . $suffix; // Color controls if ('color' == $field['type']) { $color = Kirki_Color::sanitize_hex($value); $styles[$element][$property] = $color . $units; } elseif ('background' == $field['type']) { if (isset($field['default']['color'])) { $color_mode = false !== strpos($field['default']['color'], 'rgba') ? 'color-alpha' : 'color'; $value = kirki_get_option($field['settings_raw'] . '_color'); if ('color-alpha' == $color_mode) { $bg_color = kirki_sanitize_rgba($value); } else { $bg_color = Kirki_Color::sanitize_hex($value); } } if (isset($field['default']['image'])) { $bg_image = kirki_get_option($field['settings_raw'] . '_image'); $bg_image = esc_url_raw($bg_image); } if (isset($field['default']['repeat'])) { $bg_repeat = kirki_get_option($field['settings_raw'] . '_repeat'); $bg_repeat = kirki_sanitize_bg_repeat($bg_repeat); } if (isset($field['default']['size'])) { $bg_size = kirki_get_option($field['settings_raw'] . '_size'); $bg_size = kirki_sanitize_bg_size($bg_size); } if (isset($field['default']['attach'])) { $bg_attach = kirki_get_option($field['settings_raw'] . '_attach'); $bg_attach = kirki_sanitize_bg_attach($bg_attach); } if (isset($field['default']['position'])) { $bg_position = kirki_get_option($field['settings_raw'] . '_position'); $bg_position = kirki_sanitize_bg_position($bg_position); } if (isset($field['default']['opacity']) && $field['default']['opacity']) { $bg_opacity = kirki_get_option($field['settings_raw'] . '_opacity'); $bg_opacity = kirki_sanitize_number($bg_opacity); if (isset($bg_color)) { // If we're using an opacity other than 100, then convert the color to RGBA. $bg_color = 100 != $bg_opacity ? Kirki_Color::get_rgba($bg_color, $bg_opacity) : $bg_color; } elseif (isset($bg_image)) { $element_opacity = $bg_opacity / 100; } } if (isset($bg_color)) { $styles[$element]['background-color'] = $bg_color . $units; } if (isset($bg_image) && '' != $bg_image) { $styles[$element]['background-image'] = 'url("' . $bg_image . '")' . $units; if (isset($bg_repeat)) { $styles[$element]['background-repeat'] = $bg_repeat . $units; } if (isset($bg_size)) { $styles[$element]['background-size'] = $bg_size . $units; } if (isset($bg_attach)) { $styles[$element]['background-attachment'] = $bg_attach . $units; } if (isset($bg_position)) { $styles[$element]['background-position'] = str_replace('-', ' ', $bg_position) . $units; } } } elseif (array($field['output']) && isset($field['output']['property']) && in_array($field['output']['property'], array('font-family', 'font-size', 'font-weight'))) { $is_font_family = isset($field['output']['property']) && 'font-family' == $field['output']['property'] ? true : false; $is_font_size = isset($field['output']['property']) && 'font-size' == $field['output']['property'] ? true : false; $is_font_weight = isset($field['output']['property']) && 'font-weight' == $field['output']['property'] ? true : false; if ('font-family' == $property) { $styles[$field['output']['element']]['font-family'] = $value . $units; } else { if ('font-size' == $property) { // Get the unit we're going to use for the font-size. $units = empty($units) ? 'px' : $units; $styles[$element]['font-size'] = $value . $units; } else { if ('font-weight' == $property) { $styles[$element]['font-weight'] = $value . $units; } } } } else { $styles[$element][$property] = $value . $units; } return $styles; }
/** * Gets the colors used. * * @access public * @return null|void */ public function get_colors() { $config = apply_filters('kirki/config', array()); // No need to proceed if we haven't set any colors. if ((!isset($config['color_back']) || !$config['color_back']) && (!isset($config['color_accent']) || !$config['color_accent'])) { return; } // Set the $process to true. $this->process = true; // Calculate the accent color. if (isset($config['color_accent'])) { $this->color_accent = Kirki_Color::sanitize_hex($config['color_accent']); } // Calculate the background & font colors. if (isset($config['color_back'])) { $this->color_back = Kirki_Color::sanitize_hex($config['color_back']); $this->color_font = 170 > Kirki_Color::get_brightness($this->color_back) ? '#f2f2f2' : '#222'; } if ($this->color_back) { $this->buttons_color = 170 > Kirki_Color::get_brightness($this->color_back) ? Kirki_Color::adjust_brightness($this->color_back, 80) : Kirki_Color::adjust_brightness($this->color_back, -80); $this->border_color = 170 > Kirki_Color::get_brightness($this->color_back) ? 'rgba(255,255,255,.2)' : 'rgba(0,0,0,.2)'; $this->arrows_color = 170 > Kirki_Color::get_brightness($this->color_back) ? Kirki_Color::adjust_brightness($this->color_back, 120) : Kirki_Color::adjust_brightness($this->color_back, -120); $this->section_background_color = Kirki_Color::mix_colors($this->color_back, '#ffffff', 10); } $this->controls_color = 170 > Kirki_Color::get_brightness($this->color_accent) ? '#ffffff;' : '#333333'; $this->color_accent_text = 170 > Kirki_Color::get_brightness($this->color_accent) ? Kirki_Color::adjust_brightness($this->color_accent, 120) : Kirki_Color::adjust_brightness($this->color_accent, -120); }
function kirki_get_brightness($hex) { return Kirki_Color::get_brightness($hex); }
/** * Add custom CSS rules to the head, applying our custom styles */ public function custom_css() { $color = $this->get_admin_colors(); $config = apply_filters('kirki/config', array()); // Calculate the accent color $color_accent = isset($color['icon_colors']) && isset($color['icon_colos']['focus']) ? $color['icon_colors']['focus'] : '#3498DB'; if (isset($config['color_accent'])) { $color_accent = Kirki_Color::sanitize_hex($config['color_accent']); } // Calculate the background & font colors $color_back = false; $color_font = false; if (isset($config['color_back'])) { $color_back = Kirki_Color::sanitize_hex($config['color_back']); $color_font = 170 > Kirki_Color::get_brightness($color_back) ? '#f2f2f2' : '#222'; } $border_color = 170 > Kirki_Color::get_brightness($color_back) ? 'rgba(255,255,255,.2)' : 'rgba(0,0,0,.2)'; $buttons_color = 170 > Kirki_Color::get_brightness($color_back) ? Kirki_Color::adjust_brightness($color_back, 80) : Kirki_Color::adjust_brightness($color_back, -80); $controls_color = 170 > Kirki_Color::get_brightness($color_accent) ? '#ffffff;' : '#333333'; $arrows_color = 170 > Kirki_Color::get_brightness($color_back) ? Kirki_Color::adjust_brightness($color_back, 120) : Kirki_Color::adjust_brightness($color_back, -120); $color_accent_text = 170 > Kirki_Color::get_brightness($color_accent) ? Kirki_Color::adjust_brightness($color_accent, 120) : Kirki_Color::adjust_brightness($color_accent, -120); $section_background_color = Kirki_Color::mix_colors($color_back, '#ffffff', 10); /** * Initialize the WP_Filesystem */ global $wp_filesystem; if (empty($wp_filesystem)) { require_once ABSPATH . '/wp-admin/includes/file.php'; WP_Filesystem(); } $styles = ''; /** * Include the width CSS if necessary */ if (isset($config['width'])) { $styles .= $wp_filesystem->get_contents(KIRKI_PATH . '/assets/css/customizer-dynamic-css-width.css'); /** * Replace width placeholder with actual value */ $styles = str_replace('WIDTH', $config['width'], $styles); } /** * Include the color modifications CSS if necessary */ if (false !== $color_back && false !== $color_font) { $styles .= $wp_filesystem->get_contents(KIRKI_PATH . '/assets/css/customizer-dynamic-css-colors.css'); } /** * Include generic CSS for controls */ $styles .= $wp_filesystem->get_contents(KIRKI_PATH . '/assets/css/customizer-dynamic-css.css'); /** * replace CSS placeholders with actual values */ $styles = str_replace('COLOR_BACK', $color_back, $styles); $styles = str_replace('COLOR_ACCENT_TEXT', $color_accent_text, $styles); $styles = str_replace('COLOR_ACCENT', $color_accent, $styles); $styles = str_replace('BORDER_COLOR', $border_color, $styles); $styles = str_replace('BUTTONS_COLOR', $buttons_color, $styles); $styles = str_replace('COLOR_FONT', $color_font, $styles); $styles = str_replace('CONTROLS_COLOR', $controls_color, $styles); $styles = str_replace('ARROWS_COLOR', $arrows_color, $styles); $styles = str_replace('SECTION_BACKGROUND_COLOR', $section_background_color, $styles); return $styles; }
/** * Add custom CSS rules to the head, applying our custom styles */ public function custom_css() { $color = $this->get_admin_colors(); $config = apply_filters('kirki/config', array()); // Calculate the accent color $color_accent = isset($color['icon_colors']) && isset($color['icon_colos']['focus']) ? $color['icon_colors']['focus'] : '#3498DB'; if (isset($config['color_accent'])) { $color_accent = Kirki_Color::sanitize_hex($config['color_accent']); } // Calculate the background & font colors $color_back = false; $color_font = false; if (isset($config['color_back'])) { $color_back = Kirki_Color::sanitize_hex($config['color_back']); $color_font = 170 > Kirki_Color::get_brightness($color_back) ? '#f2f2f2' : '#222'; } $styles = ''; // Width if (isset($config['width'])) { $styles .= '.wp-full-overlay-sidebar{width:' . esc_attr($config['width']) . ';}'; $styles .= '.wp-full-overlay.expanded{margin-left:' . esc_attr($config['width']) . ';}'; } if (false !== $color_back && false !== $color_font) { // Generic background color $styles .= '.wp-full-overlay-sidebar{background:' . $color_back . ';}'; // Title background color $styles .= '#customize-controls .customize-info .accordion-section-title, #customize-controls .panel-meta.customize-info .accordion-section-title:hover{background:' . $color_back . ';}'; // Borders $border_color = 170 > Kirki_Color::get_brightness($color_back) ? 'rgba(255,255,255,.2)' : 'rgba(0,0,0,.2)'; $styles .= '#customize-controls .customize-info{border-top-color:' . $border_color . ';border-bottom-color:' . $border_color . ';}'; $styles .= '.customize-section-title{border-bottom-color:' . $border_color . ';}'; $styles .= '.customize-panel-back, .customize-section-back{border-right-color:' . $border_color . ';}'; $styles .= '#customize-header-actions{border-bottom-color:' . $border_color . ';}'; $styles .= '.customize-controls-close, .customize-overlay-close{border-right-color:' . $border_color . '!important;}'; // back & close buttons color if (170 > Kirki_Color::get_brightness($color_back)) { $color = Kirki_Color::adjust_brightness($color_back, 80); } else { $color = Kirki_Color::adjust_brightness($color_back, -80); } $styles .= '.customize-panel-back:focus, .customize-panel-back:hover, .customize-section-back:focus, .customize-section-back:hover, .customize-panel-back, .customize-section-back, .customize-controls-close, .customize-overlay-close{background:' . $color . ';}'; $styles .= '.control-panel-back:focus, .control-panel-back:hover, .customize-controls-close:focus, .customize-controls-close:hover, .customize-controls-preview-toggle:focus, .customize-controls-preview-toggle:hover, .customize-overlay-close:focus, .customize-overlay-close:hover{background:' . $color . '}'; // Sections list titles $styles .= '#customize-theme-controls .accordion-section-title{background:' . $color_back . ';color:' . $color_font . ';}'; $color = 170 > Kirki_Color::get_brightness($color_accent) ? 'color:#ffffff;' : ''; $styles .= '#customize-controls .control-section .accordion-section-title:focus, #customize-controls .control-section .accordion-section-title:hover, #customize-controls .control-section.open .accordion-section-title, #customize-controls .control-section:hover>.accordion-section-title{background:' . $color_accent . ';' . $color . '}'; // Arrows if (170 > Kirki_Color::get_brightness($color_back)) { $color = Kirki_Color::adjust_brightness($color_back, 120); } else { $color = Kirki_Color::adjust_brightness($color_back, -120); } $styles .= '.accordion-section-title:after, .handlediv, .item-edit, .sidebar-name-arrow, .widget-action{color:' . $color . '}'; if (170 > Kirki_Color::get_brightness($color_accent)) { $color = Kirki_Color::adjust_brightness($color_accent, 120); } else { $color = Kirki_Color::adjust_brightness($color_accent, -120); } $styles .= '#customize-theme-controls .control-section .accordion-section-title:focus:after, #customize-theme-controls .control-section .accordion-section-title:hover:after, #customize-theme-controls .control-section.open .accordion-section-title:after, #customize-theme-controls .control-section:hover>.accordion-section-title:after{color:' . $color . '}'; // Title for active section $styles .= '.customize-section-title{background:' . $color_back . ';}'; $styles .= '.customize-section-title h3, h3.customize-section-title{color:' . $color_font . ';}'; // Active section background $styles .= '#customize-theme-controls .accordion-section-content{background:' . Kirki_Color::mix_colors($color_back, '#ffffff', 10) . ';}'; // Title color for active panels etc. $styles .= '#customize-controls .customize-info .preview-notice{color:' . $color_font . ';}'; } // Button styles $color = 170 > Kirki_Color::get_brightness($color_accent) ? '#fff' : '#222'; $styles .= '.wp-core-ui .button-primary-disabled, .wp-core-ui .button-primary.disabled, .wp-core-ui .button-primary:disabled, .wp-core-ui .button-primary[disabled]{background:' . $color_accent . ' !important;color:' . $color . ' !important;border-color:rgba(0,0,0,.1) !important;opacity:.7;}'; $styles .= '.wp-core-ui .button-primary{background-color:' . $color_accent . ';color:' . $color . ';opacity:1;}'; // Tooltip styles $styles .= '#customize-controls .customize-info .customize-help-toggle{color:' . $color_accent . ';}'; // Image-Radio styles $styles .= '.customize-control-radio-image .image.ui-buttonset label.ui-state-active{border:2px solid ' . $color_accent . ';}'; // Buttonset-Radio styles $color = 170 > Kirki_Color::get_brightness($color_accent) ? '#fff;' : '#222'; $styles .= '.customize-control-radio-buttonset label.ui-state-active{background-color:' . $color_accent . ';color:' . $color . ';}'; // Slider Controls $styles .= '.customize-control-slider .ui-slider .ui-slider-handle{background-color:' . $color_accent . ';}'; // Switch Controls $styles .= '.customize-control-switch .fs-checkbox-toggle.fs-checkbox-checked .fs-checkbox-flag{background:' . $color_accent . ';}'; // Toggle Controls $styles .= '.customize-control-toggle .fs-checkbox-toggle.fs-checkbox-checked .fs-checkbox-flag{background:' . $color_accent . ';}'; // Sortable Controls $styles .= '.customize-control-sortable ul.ui-sortable li .dashicons.visibility{color:' . $color_accent . ';}'; // Palette Controls $styles .= '.customize-control-palette label.ui-state-active.ui-button.ui-widget span.ui-button-text{border-color:' . $color_accent . ';}'; return $styles; }
/** * Calculate a color that will be readable against a specific background-color. * * @param $value string the background color in question * @return string a color that is readable against this background-color. */ public static function max_readability($value) { /** * The lumosity difference between the background color and white */ $lumosity_difference_to_white = Kirki_Color::lumosity_difference($value, '#ffffff'); /** * The lumosity difference between the background color and #333 (dark grey) */ $lumosity_difference_to_black = Kirki_Color::lumosity_difference($value, '#333333'); /** * Return whitre or #333333 depending on which lumosity difference is greater. */ return $lumosity_difference_to_black > $lumosity_difference_to_white ? '#333333' : '#ffffff'; }
public function get_colors() { $color = $this->get_admin_colors(); $config = apply_filters('kirki/config', array()); // Calculate the accent color $this->color_accent = isset($color['colors']) && isset($color['colors'][3]) ? $color['colors'][3] : '#3498DB'; if (isset($config['color_accent'])) { $this->color_accent = Kirki_Color::sanitize_hex($config['color_accent']); } // Calculate the background & font colors $this->color_back = false; $this->color_font = false; if (isset($config['color_back'])) { $this->color_back = Kirki_Color::sanitize_hex($config['color_back']); $this->color_font = 170 > Kirki_Color::get_brightness($this->color_back) ? '#f2f2f2' : '#222'; } $this->border_color = 170 > Kirki_Color::get_brightness($this->color_back) ? 'rgba(255,255,255,.2)' : 'rgba(0,0,0,.2)'; $this->buttons_color = 170 > Kirki_Color::get_brightness($this->color_back) ? Kirki_Color::adjust_brightness($this->color_back, 80) : Kirki_Color::adjust_brightness($this->color_back, -80); $this->controls_color = 170 > Kirki_Color::get_brightness($this->color_accent) ? '#ffffff;' : '#333333'; $this->arrows_color = 170 > Kirki_Color::get_brightness($this->color_back) ? Kirki_Color::adjust_brightness($this->color_back, 120) : Kirki_Color::adjust_brightness($this->color_back, -120); $this->color_accent_text = 170 > Kirki_Color::get_brightness($this->color_accent) ? Kirki_Color::adjust_brightness($this->color_accent, 120) : Kirki_Color::adjust_brightness($this->color_accent, -120); $this->section_background_color = Kirki_Color::mix_colors($this->color_back, '#ffffff', 10); }
public function test_kirki_get_brightness() { $random_color = str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT) . str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT) . str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT); $this->assertEquals(kirki_get_brightness($random_color), Kirki_Color::get_brightness($random_color)); }