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

/* Sanitization Text*/
function vegan_cafe_restaurant_sanitize_text( $vegan_cafe_restaurant_text ) {
	return wp_filter_post_kses( $vegan_cafe_restaurant_text );
}

function vegan_cafe_restaurant_sanitize_copyright_position( $vegan_cafe_restaurant_input ) {
    $vegan_cafe_restaurant_valid = array( 'right', 'left', 'center' );

    if ( in_array( $vegan_cafe_restaurant_input, $vegan_cafe_restaurant_valid, true ) ) {
        return $vegan_cafe_restaurant_input;
    } else {
        return 'right';
    }
}

function vegan_cafe_restaurant_sanitize_choices( $vegan_cafe_restaurant_input, $vegan_cafe_restaurant_setting ) {
    global $wp_customize; 
    $vegan_cafe_restaurant_control = $wp_customize->get_control( $vegan_cafe_restaurant_setting->id ); 
    if ( array_key_exists( $vegan_cafe_restaurant_input, $vegan_cafe_restaurant_control->choices ) ) {
        return $vegan_cafe_restaurant_input;
    } else {
        return $vegan_cafe_restaurant_setting->default;
    }
}

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

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