<?php
/**
 * Collection of sanitization callback functions.
 *
 * @since 1.0.0
 *
 * @package Masonry_Blog
 */

if ( ! function_exists( 'masonry_blog_sanitize_range' ) ) {
	/**
	 * Sanitizes range value.
	 *
	 * @param string $input Setting value.
	 * @param object $setting Setting object.
	 * @return string
	 */
	function masonry_blog_sanitize_range( $input, $setting ) {

		if ( $input <= $setting->manager->get_control( $setting->id )->input_attrs['max'] ) {

			if ( $input >= $setting->manager->get_control( $setting->id )->input_attrs['min'] ) {

				return absint( $input );
			}
		}
	}
}


if ( ! function_exists( 'masonry_blog_sanitize_number' ) ) {
	/**
	 * Sanitizes number value.
	 *
	 * @param string $input Setting value.
	 * @param object $setting Setting object.
	 * @return string
	 */
	function masonry_blog_sanitize_number( $input, $setting ) {

		return absint( $input );
	}
}


if ( ! function_exists( 'masonry_blog_sanitize_select' ) ) {
	/**
	 * Sanitizes single select value.
	 *
	 * @param string $input Setting value.
	 * @param object $setting Setting object.
	 * @return string
	 */
	function masonry_blog_sanitize_select( $input, $setting ) {

		$input = sanitize_key( $input );

		$choices = $setting->manager->get_control( $setting->id )->choices;

		return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
	}
}
