Template_Tag_Email_Field::validate_single( mixed $value = null )

Validates a single value for the field.

Description

Parameters

$value

(mixed) (Optional) Value to validate. When null is passed, the method assumes no value was sent.

Default value: null

Return

(mixed|awsmug\Torro_Forms\Components\WP_Error) The validated value on success, or an error object on failure.

Source

File: src/components/template-tag-email-field.php

	protected function validate_single( $value = null ) {
		$value = parent::validate_single( $value );
		if ( is_wp_error( $value ) ) {
			return $value;
		}

		if ( ! empty( $value ) ) {
			// If only a placeholder is contained, let's assume it's a valid email placeholder.
			if ( 1 === substr_count( $value, '{' ) && 1 === substr_count( $value, '}' ) && '{' === substr( $value, 0, 1 ) && '}' === substr( $value, -1, 1 ) ) {
				return $value;
			}

			if ( ! is_email( $value ) ) {
				return new WP_Error( 'field_email_invalid', sprintf( $this->manager->get_message( 'field_email_invalid' ), $value, $this->label ) );
			}
		}

		return $value;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.