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

/* Sanitization Text*/
function expert_author_sanitize_text( $expert_author_text ) {
	return wp_filter_post_kses( $expert_author_text );
}

function expert_author_sanitize_choices( $expert_author_input, $expert_author_setting ) {
    global $wp_customize; 
    $expert_author_control = $wp_customize->get_control( $expert_author_setting->id ); 
    if ( array_key_exists( $expert_author_input, $expert_author_control->choices ) ) {
        return $expert_author_input;
    } else {
        return $expert_author_setting->default;
    }
}

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

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

function expert_author_sanitize_copyright_position( $expert_author_input ) {
    $valid = array( 'right', 'left', 'center' );
    if ( in_array( $expert_author_input, $valid, true ) ) {
        return $expert_author_input;
    } else {
        return 'right';
    }
}