BP_XProfile_Field_Type_URL::pre_validate_filter( string $submitted_value = '', string|int $field_id = '' )

Modify submitted URL values before validation.

Description

The URL validation regex requires a http(s) protocol, so that all values saved in the database are fully-formed URLs. However, we still want to allow users to enter URLs without a protocol, for a better user experience. So we catch submitted URL values, and if the protocol is missing, we prepend ‘http://’ before passing to is_valid().

Parameters

$submitted_value

(string) (Optional) Raw value submitted by the user.

Default value: ''

$field_id

(string|int) (Optional) ID of the field.

Default value: ''

Return

(string)

Source

File: bp-xprofile/classes/class-bp-xprofile-field-type-url.php

	public static function pre_validate_filter( $submitted_value = '', $field_id = '' ) {

		// Allow empty URL values.
		if ( empty( $submitted_value ) ) {
			return '';
		}

		// Run some checks on the submitted value.
		if ( false === strpos( $submitted_value, ':'  ) &&
			substr( $submitted_value, 0, 1 ) !== '/' &&
			substr( $submitted_value, 0, 1 ) !== '#' &&
			! preg_match( '/^[a-z0-9-]+?\.php/i', $submitted_value )
		) {
			$submitted_value = 'http://' . $submitted_value;
		}

		return $submitted_value;
	}

Changelog

Changelog
Version Description
BuddyPress 2.1.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.