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

/* Sanitization Text*/
function expert_construction_company_sanitize_text( $expert_construction_company_text ) {
	return wp_filter_post_kses( $expert_construction_company_text );
}

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

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

function expert_construction_company_sanitize_select( $expert_construction_company_input, $expert_construction_company_setting ) {
  $expert_construction_company_input = sanitize_key( $expert_construction_company_input );
  $expert_construction_company_choices = $expert_construction_company_setting->manager->get_control( $expert_construction_company_setting->id )->choices;
  return ( array_key_exists( $expert_construction_company_input, $expert_construction_company_choices ) ? $expert_construction_company_input : $expert_construction_company_setting->default );
}

// Sanitize the input
function expert_construction_company_sanitize_sidebar_position( $expert_construction_company_input ) {
    $expert_construction_company_valid = array( 'right', 'left' );

    if ( in_array( $expert_construction_company_input, $expert_construction_company_valid ) ) {
        return $expert_construction_company_input;
    } else {
        return 'right';
    }
}

function expert_construction_company_sanitize_copyright_position( $expert_construction_company_input ) {
    $expert_construction_company_valid = array( 'right', 'left', 'center' );

    if ( in_array( $expert_construction_company_input, $expert_construction_company_valid, true ) ) {
        return $expert_construction_company_input;
    } else {
        return 'right';
    }
}

function expert_construction_company_sanitize_choices( $expert_construction_company_input, $expert_construction_company_setting ) {
    global $wp_customize; 
    $expert_construction_company_control = $wp_customize->get_control( $expert_construction_company_setting->id ); 
    if ( array_key_exists( $expert_construction_company_input, $expert_construction_company_control->choices ) ) {
        return $expert_construction_company_input;
    } else {
        return $expert_construction_company_setting->default;
    }
}

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