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());
 }
Example #2
0
 public function test_kirki_get_rgb()
 {
     $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_rgb($random_color), Kirki_Color::get_rgb($random_color));
 }
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;
}