<?php
/**
 * Sanitization functions.
 *
 * @package Matrimony
 */
//Enable/Disable
if ( ! function_exists( 'matrimonial_sanitize_switch_options' ) ) :
    /**
     * Sanitize Swtich Control.
     *
     * @since 1.0.0     
     *
    */    
    function matrimonial_sanitize_switch_options( $input ) {
        return absint( $input );
    }
endif;


// Category Selections
function matrimonial_cat_sanitize_checkbox($input){
    $matrimony_cat_list = matrimony_category_lists();
    if(array_key_exists($input,$matrimony_cat_list)){
        return $input;
    }
    else{
        return '';
    }
}
// Page Selections
if ( ! function_exists( 'matromony_pages' ) ) :

    /**
     * Sanitize dropdown pages.
     *
     * @since 1.0.0
     *
     * @param int                  $page_id Page ID.
     * @param WP_Customize_Setting $setting WP_Customize_Setting instance.
     * @return int|string Page ID if the page is published; otherwise, the setting default.
     */
    function matromony_pages( $page_id, $setting ) {

        // Ensure $input is an absolute integer.
        $page_id = absint( $page_id );

        // If $page_id is an ID of a published page, return it; otherwise, return the default.
        return ( 'publish' === get_post_status( $page_id ) ? $page_id : $setting->default );

    }

endif;
// Innter Sanitizer
function matrimony_sanitize_number( $input ) {
    $output = intval($input);
    return $output;
}

//=========================== Header Site Identity ============================================//
if ( ! function_exists( 'matrimony_sanitize_select' ) ) :
    /**
     * Sanitize select.
     *
     * @since 1.0.0
     *
     * @param mixed                $input The value to sanitize.
     * @param WP_Customize_Setting $setting WP_Customize_Setting instance.
     * @return mixed Sanitized value.
     */
    function matrimony_sanitize_select( $input, $setting ) {

        // Ensure input is a slug.
        $input = sanitize_key( $input );

        // Get list of choices from the control associated with the setting.
        $choices = $setting->manager->get_control( $setting->id )->choices;

        // If the input is a valid key, return it; otherwise, return the default.
        return ( array_key_exists( $input, $choices ) ? $input : $setting->default );

    }

endif;

if ( ! function_exists( 'matrimony_post_sanitizer' ) ) :

/**
 *  Sanitize Multiple Dropdown Taxonomies.
 *  @since 1.0.0
 */
function matrimony_post_sanitizer( $input ) {
    // Make sure we have array.
    $input = (array) $input;

    // Sanitize each array element.
    $input = array_map( 'absint', $input );

    // Remove null elements.
    $input = array_values( array_filter( $input ) );

    return $input;
}
endif;