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

/* Sanitization Text*/
function expert_videographer_sanitize_text( $expert_videographer_text ) {
	return wp_filter_post_kses( $expert_videographer_text );
}

function expert_videographer_sanitize_choices( $expert_videographer_input, $expert_videographer_setting ) {
    global $wp_customize; 
    $expert_videographer_control = $wp_customize->get_control( $expert_videographer_setting->id ); 
    if ( array_key_exists( $expert_videographer_input, $expert_videographer_control->choices ) ) {
        return $expert_videographer_input;
    } else {
        return $expert_videographer_setting->default;
    }
}

function expert_videographer_sanitize_select( $expert_videographer_input, $expert_videographer_setting ) {
  $expert_videographer_input = sanitize_key( $expert_videographer_input );
  $expert_videographer_choices = $expert_videographer_setting->manager->get_control( $expert_videographer_setting->id )->choices;
  return ( array_key_exists( $expert_videographer_input, $expert_videographer_choices ) ? $expert_videographer_input : $expert_videographer_setting->default );
}

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

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

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

function expert_videographer_sanitize_copyright_position( $expert_videographer_input ) {
    $expert_videographer_valid = array( 'right', 'left', 'center' );

    if ( in_array( $expert_videographer_input, $expert_videographer_valid, true ) ) {
        return $expert_videographer_input;
    } else {
        return 'right';
    }
}