<?php
function spasalon_sanitize_fn($wp_customize) {

    if (!function_exists('spasalon_select2_text_sanitization')) {

        function spasalon_select2_text_sanitization($input) {
            if (strpos($input, ',') !== false) {
                $input = explode(',', $input);
            }
            if (is_array($input)) {
                foreach ($input as $key => $value) {
                    $input[$key] = sanitize_text_field($value);
                }
                $input = implode(',', $input);
            } else {
                $input = sanitize_text_field($input);
            }
            return $input;
        }

    }
}

add_action('customize_register', 'spasalon_sanitize_fn');

//checkbox box sanitization function
function spasalon_sanitize_checkbox($checked) {
    // Boolean check.
    return ( ( isset($checked) && true == $checked ) ? 1 : 0 );
}

//select sanitization function
function spasalon_sanitize_select($input, $setting) {

    $input = sanitize_key($input);

    $choices = $setting->manager->get_control($setting->id)->choices;

    //return if valid
    return ( array_key_exists($input, $choices) ? $input : $setting->default );
}  

//radio box sanitization function
function spasalon_sanitize_radio($input, $setting) {

    $input = sanitize_key($input);

    $choices = $setting->manager->get_control($setting->id)->choices;

    //return if valid 
    return ( array_key_exists($input, $choices) ? $input : $setting->default );
}