<?php
/**
* Custom Functions.
*
* @package Cleaning Maintenance
*/

if( !function_exists( 'cleaning_maintenance_sanitize_sidebar_option' ) ) :

    // Sidebar Option Sanitize.
    function cleaning_maintenance_sanitize_sidebar_option( $cleaning_maintenance_input ){

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

            return $cleaning_maintenance_input;

        }

        return;

    }

endif;

if ( ! function_exists( 'cleaning_maintenance_sanitize_checkbox' ) ) :

	/**
	 * Sanitize checkbox.
	 */
	function cleaning_maintenance_sanitize_checkbox( $cleaning_maintenance_checked ) {

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

	}

endif;


if ( ! function_exists( 'cleaning_maintenance_sanitize_select' ) ) :

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

endif;

/*Radio Button sanitization*/
function cleaning_maintenance_sanitize_choices( $cleaning_maintenance_input, $cleaning_maintenance_setting ) {
    global $wp_customize;
    $cleaning_maintenance_control = $wp_customize->get_control( $cleaning_maintenance_setting->id );
    if ( array_key_exists( $cleaning_maintenance_input, $cleaning_maintenance_control->choices ) ) {
        return $cleaning_maintenance_input;
    } else {
        return $cleaning_maintenance_setting->default;
    }
}