Validate::validate_array_max( 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_max( $field ) {
		$max_arr = (int) $field->get( 'array_max', 0 );
		$value   = $field->value();

		if ( ! empty( $value ) && count( $value ) > $max_arr ) {
			$field->add_error(
				'array-max',
				sprintf(
					// Translators: placeholder contain field label.
					__( 'Maximum values allowed in field %2$s is %1$d.', 'anspress-question-answer' ),
					$max_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