<?php
/**
 * Validation functions
 *
 * @package Charityup
 */

if ( ! function_exists( 'charityup_validate_excerpt_length' ) ) :
	function charityup_validate_excerpt_length( $validity, $value ) {
		$value = intval( $value );
		if ( empty( $value ) || ! is_numeric( $value ) ) {
			$validity->add( 'required', esc_html__( 'You must supply a valid number.', 'charityup' ) );
		} elseif ( $value < 1 ) {
			$validity->add( 'min_no_of_words', esc_html__( 'Minimum no of word is 1', 'charityup' ) );
		} elseif ( $value > 100 ) {
			$validity->add( 'max_no_of_words', esc_html__( 'Maximum no of words is 100', 'charityup' ) );
		}
		return $validity;
	}
endif;

if ( ! function_exists( 'charityup_validate_cause_count' ) ) :
	function charityup_validate_cause_count( $validity, $value ) {
		$value = intval( $value );
		if ( empty( $value ) || ! is_numeric( $value ) ) {
			$validity->add( 'required', esc_html__( 'You must supply a valid number.', 'charityup' ) );
		} elseif ( $value < 3 ) {
			$validity->add( 'min_no_of_posts', esc_html__( 'Minimum no of posts is 3', 'charityup' ) );
		} elseif ( $value > 12 ) {
			$validity->add( 'max_no_of_posts', esc_html__( 'Maximum no of posts is 12', 'charityup' ) );
		}
		return $validity;
	}
endif;

if ( ! function_exists( 'charityup_validate_counter_count' ) ) :
	function charityup_validate_counter_count( $validity, $value ) {
		$value = intval( $value );
		if ( empty( $value ) || ! is_numeric( $value ) ) {
			$validity->add( 'required', esc_html__( 'You must supply a valid number.', 'charityup' ) );
		} elseif ( $value < 2 ) {
			$validity->add( 'min_no_of_posts', esc_html__( 'Minimum no of posts is 2', 'charityup' ) );
		} elseif ( $value > 4 ) {
			$validity->add( 'max_no_of_posts', esc_html__( 'Maximum no of posts is 4', 'charityup' ) );
		}
		return $validity;
	}
endif;

if ( ! function_exists( 'charityup_validate_blog_count' ) ) :
	function charityup_validate_blog_count( $validity, $value ) {
		$value = intval( $value );
		if ( empty( $value ) || ! is_numeric( $value ) ) {
			$validity->add( 'required', esc_html__( 'You must supply a valid number.', 'charityup' ) );
		} elseif ( $value < 3 ) {
			$validity->add( 'min_no_of_posts', esc_html__( 'Minimum no of posts is 3', 'charityup' ) );
		} elseif ( $value > 12 ) {
			$validity->add( 'max_no_of_posts', esc_html__( 'Maximum no of posts is 12', 'charityup' ) );
		}
		return $validity;
	}
endif;
