<?php
/**
 * Customizer: Sanitization Callbacks
 *
 * This file demonstrates how to define sanitization callback functions for various data types.
 * 
 * @package   Film Studio
 * @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 film_studio_sanitize_checkbox( $film_studio_checked ) {
	return ( ( isset( $film_studio_checked ) && true == $film_studio_checked ) ? true : false );
}

function film_studio_sanitize_choices( $film_studio_input, $film_studio_setting ) {
    global $wp_customize; 
    $film_studio_control = $wp_customize->get_control( $film_studio_setting->id ); 
    if ( array_key_exists( $film_studio_input, $film_studio_control->choices ) ) {
        return $film_studio_input;
    } else {
        return $film_studio_setting->default;
    }
}

/* Sanitization Text*/
function film_studio_sanitize_text( $film_studio_text ) {
	return wp_filter_post_kses( $film_studio_text );
}

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

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

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

// Sanitize the input
function film_studio_sanitize_sidebar_position( $film_studio_input ) {
    $film_studio_valid = array( 'right', 'left' );

    if ( in_array( $film_studio_input, $film_studio_valid ) ) {
        return $film_studio_input;
    } else {
        return 'right';
    }
}

function film_studio_sanitize_copyright_position( $film_studio_input ) {
    $film_studio_valid = array( 'right', 'left', 'center' );

    if ( in_array( $film_studio_input, $film_studio_valid, true ) ) {
        return $film_studio_input;
    } else {
        return 'right';
    }
}