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

if ( ! function_exists( 'charity_elite_validate_excerpt_length' ) ) :
	function charity_elite_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.', 'charity-elite' ) );
		} elseif ( $value < 1 ) {
			$validity->add( 'min_no_of_words', esc_html__( 'Minimum no of words is 1', 'charity-elite' ) );
		} elseif ( $value > 100 ) {
			$validity->add( 'max_no_of_words', esc_html__( 'Maximum no of words is 100', 'charity-elite' ) );
		}
		return $validity;
	}
endif;

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