<?php

/**
 * Goblog Free Add Sanitization Customize.
 *
 * @package Goblog Free
 * @subpackage Goblog Free
 * @since 1.0
 */

// Switch Sanitization
if (!function_exists('goblog_free_switch_sanitization')) {
    function goblog_free_switch_sanitization($input)
    {
        if (true === $input) {
            return 1;
        } else {
            return 0;
        }
    }
}

// Range Sanitization
if (!function_exists('goblog_free_range_sanitization')) {
    function goblog_free_range_sanitization($input)
    {
        return absint($input);
    }
}

// Radio Text Sanitization
if (!function_exists('goblog_free_text_image_sanitization')) {
    function goblog_free_text_image_sanitization($input, $setting)
    {
        //get the list of possible radio box or select options
        $choices = $setting->manager->get_control($setting->id)->choices;

        if (array_key_exists($input, $choices)) {
            return sanitize_text_field($input);
        } else {
            return $setting->default;
        }
    }
}

// Google Font Sanitization
if (!function_exists('goblog_free_google_font_sanitization')) {
    function goblog_free_google_font_sanitization($input)
    {
        $val =  json_decode($input, true);
        if (is_array($val)) {
            foreach ($val as $key => $value) {
                $val[$key] = sanitize_text_field($value);
            }
            $input = json_encode($val);
        } else {
            $input = json_encode(sanitize_text_field($val));
        }
        return $input;
    }
}
