<?php 
/**
 * The validator file.
 *
 * @package Smart_Post_Show_Pro
 * @subpackage Smart_Post_Show_Pro/admin/views
 */

if ( ! defined( 'ABSPATH' ) ) {
	die;
} // Cannot access directly.

if ( ! function_exists( 'spf_validate_email' ) ) {
	/**
	 *
	 * Email validate
	 *
	 * @param mixed $value email.
	 * @since 1.0.0
	 * @version 1.0.0
	 */
	function spf_validate_email( $value ) {

		if ( ! filter_var( $value, FILTER_VALIDATE_EMAIL ) ) {
			return esc_html__( 'Please write a valid email address!', 'smart-post-show-pro' );
		}

	}
}

if ( ! function_exists( 'spf_validate_numeric' ) ) {
	/**
	 *
	 * Numeric validate
	 *
	 * @param mixed $value number.
	 * @since 1.0.0
	 * @version 1.0.0
	 */
	function spf_validate_numeric( $value ) {

		if ( ! is_numeric( $value ) ) {
			return esc_html__( 'Please write a numeric data!', 'smart-post-show-pro' );
		}

	}
}

if ( ! function_exists( 'spf_validate_required' ) ) {
	/**
	 *
	 * Required validate
	 *
	 * @param mixed $value value.
	 * @since 1.0.0
	 * @version 1.0.0
	 */
	function spf_validate_required( $value ) {

		if ( empty( $value ) ) {
			return esc_html__( 'Error! This field is required!', 'smart-post-show-pro' );
		}

	}
}

if ( ! function_exists( 'spf_validate_url' ) ) {
	/**
	 *
	 * URL validate
	 *
	 * @param mixed $value url.
	 * @since 1.0.0
	 * @version 1.0.0
	 */
	function spf_validate_url( $value ) {

		if ( ! filter_var( $value, FILTER_VALIDATE_URL ) ) {
			return esc_html__( 'Please write a valid url!', 'smart-post-show-pro' );
		}

	}
}

if ( ! function_exists( 'spf_customize_validate_email' ) ) {
	/**
	 *
	 * Email validate for Customize
	 *
	 * @param mixed $validity email.
	 * @param mixed $value value.
	 * @param mixed $wp_customize customize.
	 * @since 1.0.0
	 * @version 1.0.0
	 */
	function spf_customize_validate_email( $validity, $value, $wp_customize ) {

		if ( ! sanitize_email( $value ) ) {
			$validity->add( 'required', esc_html__( 'Please write a valid email address!', 'smart-post-show-pro' ) );
		}

		return $validity;

	}
}

if ( ! function_exists( 'spf_customize_validate_numeric' ) ) {
	/**
	 *
	 * Numeric validate for Customize
	 *
	 * @param mixed $validity number.
	 * @param mixed $value value.
	 * @param mixed $wp_customize customize.
	 * @since 1.0.0
	 * @version 1.0.0
	 */
	function spf_customize_validate_numeric( $validity, $value, $wp_customize ) {

		if ( ! is_numeric( $value ) ) {
			$validity->add( 'required', esc_html__( 'Please write a numeric data!', 'smart-post-show-pro' ) );
		}

		return $validity;

	}
}

if ( ! function_exists( 'spf_customize_validate_required' ) ) {
	/**
	 *
	 * Required validate for Customize
	 *
	 * @param mixed $validity validity.
	 * @param mixed $value value.
	 * @param mixed $wp_customize customize.
	 * @since 1.0.0
	 * @version 1.0.0
	 */
	function spf_customize_validate_required( $validity, $value, $wp_customize ) {

		if ( empty( $value ) ) {
			$validity->add( 'required', esc_html__( 'Error! This field is required!', 'smart-post-show-pro' ) );
		}

		return $validity;

	}
}

if ( ! function_exists( 'spf_customize_validate_url' ) ) {
	/**
	 *
	 * URL validate for Customize
	 *
	 * @param mixed $validity url.
	 * @param mixed $value value.
	 * @param mixed $wp_customize customize.
	 * @since 1.0.0
	 * @version 1.0.0
	 */
	function spf_customize_validate_url( $validity, $value, $wp_customize ) {

		if ( ! filter_var( $value, FILTER_VALIDATE_URL ) ) {
			$validity->add( 'required', esc_html__( 'Please write a valid url!', 'smart-post-show-pro' ) );
		}

		return $validity;

	}
}
