_make_url_clickable_cb

Callback to convert URI match to HTML A element.

Description

(string) _make_url_clickable_cb( (array) $matches ); 

This function was backported from 2.5.0 to 2.3.2. Regex callback for make_clickable().

Returns (string)

HTML A element with URI address.

Parameters (1)

0. $matches (array)
Single Regex Match.

Usage

  1. if ( !function_exists( '_make_url_clickable_cb' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // Single Regex Match. 
  5. $matches = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = _make_url_clickable_cb($matches); 
  9.  

Defined (1)

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

/wp-includes/formatting.php  
  1. function _make_url_clickable_cb( $matches ) { 
  2. $url = $matches[2]; 
  3.  
  4. if ( ')' == $matches[3] && strpos( $url, '(' ) ) { 
  5. // If the trailing character is a closing parethesis, and the URL has an opening parenthesis in it, add the closing parenthesis to the URL. 
  6. // Then we can let the parenthesis balancer do its thing below. 
  7. $url .= $matches[3]; 
  8. $suffix = ''; 
  9. } else { 
  10. $suffix = $matches[3]; 
  11.  
  12. // Include parentheses in the URL only if paired 
  13. while ( substr_count( $url, '(' ) < substr_count( $url, ')' ) ) { 
  14. $suffix = strrchr( $url, ')' ) . $suffix; 
  15. $url = substr( $url, 0, strrpos( $url, ')' ) ); 
  16.  
  17. $url = esc_url($url); 
  18. if ( empty($url) ) 
  19. return $matches[0]; 
  20.  
  21. return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $suffix;