wc_is_valid_url

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

Description

wc_is_valid_url( (string) $url ); 

and pass FILTER_VALIDATE_URL validation.

Parameters (1)

0. $url (string)
The url.

Usage

  1. if ( !function_exists( 'wc_is_valid_url' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-conditional-functions.php'; 
  3.  
  4. // The url. 
  5. $url = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_is_valid_url($url); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-conditional-functions.php  
  1. function wc_is_valid_url( $url ) { 
  2.  
  3. // Must start with http:// or https:// 
  4. if ( 0 !== strpos( $url, 'http://' ) && 0 !== strpos( $url, 'https://' ) ) { 
  5. return false; 
  6.  
  7. // Must pass validation 
  8. if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) { 
  9. return false; 
  10.  
  11. return true;