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

/* Sanitization Text*/
function pet_house_sanitize_text( $pet_house_text ) {
	return wp_filter_post_kses( $pet_house_text );
}

function pet_house_sanitize_choices( $pet_house_input, $pet_house_setting ) {
    global $wp_customize; 
    $pet_house_control = $wp_customize->get_control( $pet_house_setting->id ); 
    if ( array_key_exists( $pet_house_input, $pet_house_control->choices ) ) {
        return $pet_house_input;
    } else {
        return $pet_house_setting->default;
    }
}

function pet_house_sanitize_select( $pet_house_input, $pet_house_setting ) {
  $pet_house_input = sanitize_key( $pet_house_input );
  $pet_house_choices = $pet_house_setting->manager->get_control( $pet_house_setting->id )->choices;
  return ( array_key_exists( $pet_house_input, $pet_house_choices ) ? $pet_house_input : $pet_house_setting->default );
}

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

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

function pet_house_sanitize_number_absint( $pet_house_number, $pet_house_setting ) {
  // Ensure $pet_house_number is an absolute integer (whole number, zero or greater).
  $pet_house_number = absint( $pet_house_number );

  // If the input is an absolute integer, return it; otherwise, return the default
  return ( $pet_house_number ? $pet_house_number : $pet_house_setting->default );
}

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

function pet_house_sanitize_copyright_position( $pet_house_input ) {
  $pet_house_valid = array( 'right', 'left', 'center' );

  if ( in_array( $pet_house_input, $pet_house_valid, true ) ) {
      return $pet_house_input;
  } else {
      return 'right';
  }
}