wc_is_valid_url( string $url )

Simple check for validating a URL, it must start with http:// or https://.


Description Description

and pass FILTER_VALIDATE_URL validation.


Parameters Parameters

$url

(Required) to check.


Top ↑

Return Return

(bool)


Top ↑

Source Source

File: includes/wc-conditional-functions.php

function wc_is_valid_url( $url ) {

	// Must start with http:// or https://.
	if ( 0 !== strpos( $url, 'http://' ) && 0 !== strpos( $url, 'https://' ) ) {
		return false;
	}

	// Must pass validation.
	if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
		return false;
	}

	return true;
}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.