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

/* Sanitization Text*/
function expert_ngo_volunteer_sanitize_text( $expert_ngo_volunteer_text ) {
	return wp_filter_post_kses( $expert_ngo_volunteer_text );
}

function expert_ngo_volunteer_sanitize_choices( $expert_ngo_volunteer_input, $expert_ngo_volunteer_setting ) {
    global $wp_customize; 
    $expert_ngo_volunteer_control = $wp_customize->get_control( $expert_ngo_volunteer_setting->id ); 
    if ( array_key_exists( $expert_ngo_volunteer_input, $expert_ngo_volunteer_control->choices ) ) {
        return $expert_ngo_volunteer_input;
    } else {
        return $expert_ngo_volunteer_setting->default;
    }
}

function expert_ngo_volunteer_sanitize_select( $expert_ngo_volunteer_input, $expert_ngo_volunteer_setting ) {
  $expert_ngo_volunteer_input = sanitize_key( $expert_ngo_volunteer_input );
  $expert_ngo_volunteer_choices = $expert_ngo_volunteer_setting->manager->get_control( $expert_ngo_volunteer_setting->id )->choices;
  return ( array_key_exists( $expert_ngo_volunteer_input, $expert_ngo_volunteer_choices ) ? $expert_ngo_volunteer_input : $expert_ngo_volunteer_setting->default );
}

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

// Sanitize the input
function expert_ngo_volunteer_sanitize_sidebar_position( $expert_ngo_volunteer_input ) {
    $expert_ngo_volunteer_valid = array( 'right', 'left' );

    if ( in_array( $expert_ngo_volunteer_input, $expert_ngo_volunteer_valid ) ) {
        return $expert_ngo_volunteer_input;
    } else {
        return 'right';
    }
}

function expert_ngo_volunteer_sanitize_copyright_position( $expert_ngo_volunteer_input ) {
    $expert_ngo_volunteer_valid = array( 'right', 'left', 'center' );

    if ( in_array( $expert_ngo_volunteer_input, $expert_ngo_volunteer_valid, true ) ) {
        return $expert_ngo_volunteer_input;
    } else {
        return 'right';
    }
}

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