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()); }
function kirki_get_rgba($hex = '#fff', $opacity = 100) { $hex = kirki_sanitize_hex($hex); // Make sure that opacity is properly formatted : // Set the opacity to 100 if a larger value has been entered by mistake. // If a negative value is used, then set to 0. // If an opacity value is entered in a decimal form (for example 0.25), then multiply by 100. if ($opacity >= 100) { $opacity = 100; } elseif ($opacity < 0) { $opacity = 0; } elseif ($opacity < 1 && $opacity != 0) { $opacity = $opacity * 100; } else { $opacity = $opacity; } // Divide the opacity by 100 to end-up with a CSS value for the opacity $opacity = $opacity / 100; $color = 'rgba(' . kirki_get_rgb($hex, true) . ', ' . $opacity . ')'; return $color; }
/** * Apply custom backgrounds to our page. */ function kirki_background_css() { $controls = apply_filters('kirki/controls', array()); $config = apply_filters('kirki/config', array()); if (isset($controls)) { foreach ($controls as $control) { if ('background' == $control['type']) { // Apply custom CSS if we've set the 'output'. if (!is_null($control['output'])) { $bg_color = kirki_sanitize_hex(get_theme_mod($control['setting'] . '_color', $control['default']['color'])); $bg_image = get_theme_mod($control['setting'] . '_image', $control['default']['image']); $bg_repeat = get_theme_mod($control['setting'] . '_repeat', $control['default']['repeat']); $bg_size = get_theme_mod($control['setting'] . '_size', $control['default']['size']); $bg_attach = get_theme_mod($control['setting'] . '_attach', $control['default']['attach']); $bg_position = get_theme_mod($control['setting'] . '_position', $control['default']['position']); $bg_opacity = get_theme_mod($control['setting'] . '_opacity', $control['default']['opacity']); if (false != $control['default']['opacity']) { $bg_position = get_theme_mod($control['setting'] . '_opacity', $control['default']['opacity']); // If we're using an opacity other than 100, then convert the color to RGBA. if (100 != $bg_opacity) { $bg_color = kirki_get_rgba($bg_color, $bg_opacity); } } // HTML Background $styles = $control['output'] . '{'; $styles .= 'background-color:' . $bg_color . ';'; if ('' != $bg_image) { $styles .= 'background-image: url("' . $bg_image . '");'; $styles .= 'background-repeat: ' . $bg_repeat . ';'; $styles .= 'background-size: ' . $bg_size . ';'; $styles .= 'background-attachment: ' . $bg_attach . ';'; $styles .= 'background-position: ' . str_replace('-', ' ', $bg_position) . ';'; } $styles .= '}'; } wp_add_inline_style($config['stylesheet_id'], $styles); } } } }
public function test_kirki_sanitize_hex() { $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_sanitize_hex($random_color), Kirki_Color::sanitize_hex($random_color)); }