<?php
/**
* Custom Functions.
*
* @package Home Construction Builder
*/

if( !function_exists( 'home_construction_builder_sanitize_sidebar_option' ) ) :

    // Sidebar Option Sanitize.
    function home_construction_builder_sanitize_sidebar_option( $home_construction_builder_input ){

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

            return $home_construction_builder_input;

        }

        return;

    }

endif;

if ( ! function_exists( 'home_construction_builder_sanitize_checkbox' ) ) :

	/**
	 * Sanitize checkbox.
	 */
	function home_construction_builder_sanitize_checkbox( $home_construction_builder_checked ) {

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

	}

endif;


if ( ! function_exists( 'home_construction_builder_sanitize_select' ) ) :

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

endif;

/*Radio Button sanitization*/
function home_construction_builder_sanitize_choices( $home_construction_builder_input, $home_construction_builder_setting ) {
    global $wp_customize;
    $home_construction_builder_control = $wp_customize->get_control( $home_construction_builder_setting->id );
    if ( array_key_exists( $home_construction_builder_input, $home_construction_builder_control->choices ) ) {
        return $home_construction_builder_input;
    } else {
        return $home_construction_builder_setting->default;
    }
}