Validate::validate_array_min( object $field )

Description #

Validate if there are minimum items in an array.

Parameters #

  • $field
    object (Required) Instance of @see AP_Field object.

Source #

File: lib/class-validate.php

	public static function validate_array_min( $field ) {
		$min_arr = $field->get( 'array_min', 0 );
		$value   = $field->value();

		if ( $min_arr > 0 && ( empty( $value ) || ! is_array( $value ) || $min_arr > count( $value ) ) ) {
			$field->add_error(
				'array-min',
				sprintf(
					// Translators: placeholder contain field label.
					__( 'Minimum %1$d values are required in field %2$s.', 'anspress-question-answer' ),
					$min_arr,
					$field->get( 'label' )
				)
			);
		}
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment