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

/* Sanitization Text*/
function islamic_trust_sanitize_text( $islamic_trust_text ) {
	return wp_filter_post_kses( $islamic_trust_text );
}

// Sanitize the input
function islamic_trust_sanitize_sidebar_position( $islamic_trust_input ) {
    $islamic_trust_valid = array( 'right', 'left' );

    if ( in_array( $islamic_trust_input, $islamic_trust_valid ) ) {
        return $islamic_trust_input;
    } else {
        return 'right';
    }
}

function islamic_trust_sanitize_copyright_position( $islamic_trust_input ) {
    $islamic_trust_valid = array( 'right', 'left', 'center' );

    if ( in_array( $islamic_trust_input, $islamic_trust_valid, true ) ) {
        return $islamic_trust_input;
    } else {
        return 'right';
    }
}

function islamic_trust_sanitize_choices( $islamic_trust_input, $islamic_trust_setting ) {
    global $wp_customize; 
    $islamic_trust_control = $wp_customize->get_control( $islamic_trust_setting->id ); 
    if ( array_key_exists( $islamic_trust_input, $islamic_trust_control->choices ) ) {
        return $islamic_trust_input;
    } else {
        return $islamic_trust_setting->default;
    }
}

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

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