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

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

/* Sanitization Text*/
function solar_system_company_sanitize_text( $solar_system_company_text ) {
	return wp_filter_post_kses( $solar_system_company_text );
}

function solar_system_company_sanitize_choices( $solar_system_company_input, $solar_system_company_setting ) {
    global $wp_customize; 
    $solar_system_company_control = $wp_customize->get_control( $solar_system_company_setting->id ); 
    if ( array_key_exists( $solar_system_company_input, $solar_system_company_control->choices ) ) {
        return $solar_system_company_input;
    } else {
        return $solar_system_company_setting->default;
    }
}

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

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

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