type(); } /** * Checks the address. * * @param Field $field Field being validated. * @param mixed $value Sanitised value. * * @return ValidationError|null The failure, or null when the value passes. */ public function validate( Field $field, mixed $value ): ?ValidationError { $url = (string) $value; $scheme = wp_parse_url( $url, PHP_URL_SCHEME ); $host = wp_parse_url( $url, PHP_URL_HOST ); $valid = is_string( $scheme ) && is_string( $host ) && '' !== $host && in_array( strtolower( $scheme ), self::SCHEMES, true ) && false !== filter_var( $url, FILTER_VALIDATE_URL ); if ( $valid ) { return null; } return new ValidationError( '', 'invalid_url', __( 'Please enter a valid web address, starting with http:// or https://.', 'devplugins-custom-form-builder' ) ); } }