Field::validate()

Description #

Validate current field.

Source #

File: lib/form/class-field.php

	public function validate() {
		if ( true === $this->validated ) {
			return;
		}

		if ( ! empty( $this->validate_cb ) ) {
			foreach ( (array) $this->validate_cb as $validate ) {
				// Callback for validating field type.
				$cb = 'validate_' . trim( $validate );

				if ( method_exists( 'AnsPress\Form\Validate', $cb ) ) {
					call_user_func_array( 'AnsPress\Form\Validate::' . $cb, array( $this ) );
				}

				/**
				 * Custom validation callback.
				 *
				 * @param string $field_name CUrrent field.
				 * @param object $field CUrrent field.
				 * @since 4.1.7
				 */
				apply_filters_ref_array( "ap_field_{$cb}", array( $this->field_name, $this ) );
			}

			$this->validated = true;
		}
	}

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