<?php
/**
 * Customizer: Sanitization Callbacks
 *
 * This file demonstrates how to define sanitization callback functions for various data types.
 * 
 * @package   LED TV
 * @copyright Copyright (c) 2015, WordPress Theme Review Team
 * @license   http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License, v2 (or newer)
 */

function led_tv_sanitize_checkbox( $led_tv_checked ) {
	return ( ( isset( $led_tv_checked ) && true == $led_tv_checked ) ? true : false );
}

/* Sanitization Text*/
function led_tv_sanitize_text( $led_tv_text ) {
	return wp_filter_post_kses( $led_tv_text );
}

function led_tv_sanitize_choices( $led_tv_input, $led_tv_setting ) {
    global $wp_customize; 
    $led_tv_l = $wp_customize->get_control( $led_tv_setting->id ); 
    if ( array_key_exists( $led_tv_input, $led_tv_l->choices ) ) {
        return $led_tv_input;
    } else {
        return $led_tv_setting->default;
    }
}

function led_tv_sanitize_phone_number( $led_tv_phone ) {
    return preg_replace( '/[^\d+]/', '', $led_tv_phone );
}

function led_tv_sanitize_copyright_position( $led_tv_input ) {
    $led_tv_valid = array( 'right', 'left', 'center' );

    if ( in_array( $led_tv_input, $led_tv_valid, true ) ) {
        return $led_tv_input;
    } else {
        return 'right';
    }
}

// Sanitization callback function for numeric input
function led_tv_sanitize_numeric_input($led_tv_input) {
    // Remove any non-numeric characters
    return preg_replace('/[^0-9]/', '', $led_tv_input);
}

// Sanitization callback function for logo width
function led_tv_sanitize_logo_width($led_tv_input) {
    $led_tv_input = absint($led_tv_input); // Convert to integer
    // Ensure the value is between 1 and 150
    return ($led_tv_input >= 1 && $led_tv_input <= 300) ? $led_tv_input : 150; // Default to 270 if out of range
  }
  