<?php
/**
* Custom Functions.
*
* @package Event Decorations
*/

if( !function_exists( 'event_decorations_sanitize_sidebar_option' ) ) :

    // Sidebar Option Sanitize.
    function event_decorations_sanitize_sidebar_option( $event_decorations_input ){

        $event_decorations_metabox_options = array( 'global-sidebar','left-sidebar','right-sidebar','no-sidebar' );
        if( in_array( $event_decorations_input,$event_decorations_metabox_options ) ){

            return $event_decorations_input;

        }

        return;

    }

endif;

if ( ! function_exists( 'event_decorations_sanitize_checkbox' ) ) :

	/**
	 * Sanitize checkbox.
	 */
	function event_decorations_sanitize_checkbox( $event_decorations_checked ) {

		return ( ( isset( $event_decorations_checked ) && true === $event_decorations_checked ) ? true : false );

	}

endif;


if ( ! function_exists( 'event_decorations_sanitize_select' ) ) :

    /**
     * Sanitize select.
     */
    function event_decorations_sanitize_select( $event_decorations_input, $event_decorations_setting ) {
        $event_decorations_input = sanitize_text_field( $event_decorations_input );
        $choices = $event_decorations_setting->manager->get_control( $event_decorations_setting->id )->choices;
        return ( array_key_exists( $event_decorations_input, $choices ) ? $event_decorations_input : $event_decorations_setting->default );
    }

endif;

/*Radio Button sanitization*/
function event_decorations_sanitize_choices( $input, $setting ) {
    global $wp_customize;
    $control = $wp_customize->get_control( $setting->id );
    if ( array_key_exists( $input, $control->choices ) ) {
        return $input;
    } else {
        return $setting->default;
    }
}