acf_field_url::validate_valuepublicACF 5.0.0

Validate the fields value is correctly formatted as a URL

Method of the class: acf_field_url{}

No Hooks.

Returns

mixed. Boolean true if valid, a validation error message string if not.

Usage

$acf_field_url = new acf_field_url();
$acf_field_url->validate_value( $valid, $value, $field, $input );
$valid(mixed) (required)
The current validity of the field value. Boolean true if valid, a validation error message string if not.
$value(string) (required)
The value of the field.
$field(array) (required)
Field object array.
$input(string) (required)
The form input name for this field.

Changelog

Since 5.0.0 Introduced.

acf_field_url::validate_value() code ACF 6.8.8

public function validate_value( $valid, $value, $field, $input ) {

	// bail early if empty
	if ( empty( $value ) ) {
		return $valid;
	}

	if ( strpos( $value, '://' ) !== false ) {

		// url
	} elseif ( strpos( $value, '//' ) === 0 ) {

		// protocol relative url
	} else {
		$valid = __( 'Value must be a valid URL', 'acf' );
	}

	// return
	return $valid;
}