plugin development – How can I add transparent color option in my color setting?

Question

I have created font color settings at customizer but it does not include transparent color, How can I add transparent option also.

enter code here

class site_font_color {
public static function register ( $wp_customize ) {

    $wp_customize->add_setting('site_emakers_fontcolor', array(
        'default' => 'No'
    ));

    $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'site_emakers_fontcolor-control', array(
        'label' => 'Display the Site Font Color?',
        'section' => 'colors',
        'settings' => 'site_emakers_fontcolor',
        'type' => 'select',
        'choices' => array('No'=> 'No', 'Yes' => 'Yes')
    )));



    $wp_customize->add_setting( 'site_emakers_fontcolor',
        array(
            'default'    => '#000000',
            'type'       => 'theme_mod',
            'capability' => 'edit_theme_options',
            'transport'  => 'refresh',
            'priority'   => 120,
            'sanitize_callback'  => 'esc_attr',
        )
    );

    $wp_customize->add_control( new WP_Customize_Color_Control(
        $wp_customize,
        'mytheme_site_emakers_fontcolor',
        array(
            'label'      => __( 'Site Font Color', 'customtheme' ),
            'settings'   => 'site_emakers_fontcolor',
            'priority'   => 10,
            'section'    => 'colors',
        )
    ) );

}


public static function site_output() {
    ?>

    <style type="text/css">

        <?php self::generate_css('.site *, :not(.btn-secondary, .btn)',  'color', 'site_emakers_fontcolor'); ?>
    </style>

    <?php
}


public static function generate_css( $selector, $style, $mod_name, $prefix='', $postfix='', $echo=true ) {
    $return = '';
    $mod = get_theme_mod($mod_name);
    if ( ! empty( $mod ) ) {
        $return = sprintf('%s { %s:%s; }',
            $selector,
            $style,
            $prefix.$mod.$postfix
        );
        if ( $echo ) {
            echo $return;
        }
    }
    return $return;
}

}

add_action( ‘customize_register’ , array( ‘site_font_color’ , ‘register’ ) );

add_action( ‘wp_head’ , array( ‘site_font_color’ , ‘site_output’ ) );

0
Babita Verma 2 weeks 2021-05-31T03:42:39-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse