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

/* Sanitization Text*/
function expert_ac_repair_sanitize_text( $expert_ac_repair_text ) {
	return wp_filter_post_kses( $expert_ac_repair_text );
}

function expert_ac_repair_sanitize_dropdown_pages( $expert_ac_repair_page_id, $expert_ac_repair_setting ) {
  // Ensure $expert_ac_repair_input is an absolute integer.
  $expert_ac_repair_page_id = absint( $expert_ac_repair_page_id );
  // If $expert_ac_repair_page_id is an ID of a published page, return it; otherwise, return the default.
  return ( 'publish' == get_post_status( $expert_ac_repair_page_id ) ? $expert_ac_repair_page_id : $expert_ac_repair_setting->default );
}

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

// Sanitize the input
function expert_ac_repair_sanitize_sidebar_position( $expert_ac_repair_input ) {
    $expert_ac_repair_valid = array( 'right', 'left' );

    if ( in_array( $expert_ac_repair_input, $expert_ac_repair_valid ) ) {
        return $expert_ac_repair_input;
    } else {
        return 'right';
    }
}

function expert_ac_repair_sanitize_copyright_position( $expert_ac_repair_input ) {
    $expert_ac_repair_valid = array( 'right', 'left', 'center' );

    if ( in_array( $expert_ac_repair_input, $expert_ac_repair_valid, true ) ) {
        return $expert_ac_repair_input;
    } else {
        return 'right';
    }
}

function expert_ac_repair_sanitize_choices( $expert_ac_repair_input, $expert_ac_repair_setting ) {
    global $wp_customize; 
    $expert_ac_repair_control = $wp_customize->get_control( $expert_ac_repair_setting->id ); 
    if ( array_key_exists( $expert_ac_repair_input, $expert_ac_repair_control->choices ) ) {
        return $expert_ac_repair_input;
    } else {
        return $expert_ac_repair_setting->default;
    }
}

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