<?php
/**
 * Sanitization Callbacks
 * 
 * @package mediapulse
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * array sanitization callback
*/
function mediapulse_sanitize_array( $value ){
        if ( is_array( $value ) ) {
                foreach ( $value as $key => $subvalue ) {
                        $value[ $key ] = esc_attr( $subvalue );
                }
                return $value;
        }
        return esc_attr( $value );
}

/**
 * Checkbox sanitization callback
*/
function mediapulse_sanitize_checkbox($checked) {
    // Boolean check.
    return ( ( isset($checked) && true == $checked ) ? true : false );
}

/**
 * Select choices sanitization callback
*/
function mediapulse_sanitize_select($input, $setting) {
    //input must be a slug: lowercase alphanumeric characters, dashes and underscores are allowed only
    $input = sanitize_key($input);
    //get the list of possible radio box options 
    $choices = $setting->manager->get_control($setting->id)->choices;
    //return input if valid or return default option
    return ( array_key_exists($input, $choices) ? $input : $setting->default );
}

/**
 * Text sanitization callback
*/
function mediapulse_sanitize_text($input) {
    return wp_kses_post(force_balance_tags($input));
}