clean_url

Checks and cleans a URL.

Description

(string) clean_url( (string) $url, (constant) $protocols = null, (string) $context = 'display' ); 

A number of characters are removed from the URL. If the URL is for displaying (the default behaviour) ampersands are also replaced. The clean_url filter is applied to the returned cleaned URL.

Returns (string)

The cleaned $url after the {@see 'clean_url'} filter is applied.

Parameters (3)

0. $url (string)
The URL to be cleaned.
1. $protocols — Optional. (constant) => null
An array of acceptable protocols.
2. $context — Optional. (string) => 'display'
How the URL will be used. Default is display..

Usage

  1. if ( !function_exists( 'clean_url' ) ) { 
  2. require_once ABSPATH . WPINC . '/deprecated.php'; 
  3.  
  4. // The URL to be cleaned. 
  5. $url = ''; 
  6.  
  7. // Optional. An array of acceptable protocols. 
  8. $protocols = null; 
  9.  
  10. // Optional. How the URL will be used. Default is 'display'. 
  11. $context = 'display'; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = clean_url($url, $protocols, $context); 
  15.  

Defined (1)

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

/wp-includes/deprecated.php  
  1. function clean_url( $url, $protocols = null, $context = 'display' ) { 
  2. if ( $context == 'db' ) 
  3. _deprecated_function( 'clean_url( $context = \'db\' )', '3.0.0', 'esc_url_raw()' ); 
  4. else 
  5. _deprecated_function( __FUNCTION__, '3.0.0', 'esc_url()' ); 
  6. return esc_url( $url, $protocols, $context );