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

/* Sanitization Text*/
function mobile_app_launch_sanitize_text( $mobile_app_launch_text ) {
	return wp_filter_post_kses( $mobile_app_launch_text );
}

function mobile_app_launch_sanitize_copyright_position( $mobile_app_launch_input ) {
    $mobile_app_launch_valid = array( 'right', 'left', 'center' );

    if ( in_array( $mobile_app_launch_input, $mobile_app_launch_valid, true ) ) {
        return $mobile_app_launch_input;
    } else {
        return 'right';
    }
}

function mobile_app_launch_sanitize_choices( $mobile_app_launch_input, $mobile_app_launch_setting ) {
    global $wp_customize; 
    $mobile_app_launch_control = $wp_customize->get_control( $mobile_app_launch_setting->id ); 
    if ( array_key_exists( $mobile_app_launch_input, $mobile_app_launch_control->choices ) ) {
        return $mobile_app_launch_input;
    } else {
        return $mobile_app_launch_setting->default;
    }
}

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

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