wpp_linkifyYouTubeURLs

The WooCommerce PDF & Print wpp linkifyYouTubeURLs function.

Description

wpp_linkifyYouTubeURLs( $text ); 

Parameters (1)

0. $text
The text.

Usage

  1. if ( !function_exists( 'wpp_linkifyYouTubeURLs' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-pdf-print/functions.php'; 
  3.  
  4. // The text. 
  5. $text = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wpp_linkifyYouTubeURLs($text); 
  9.  

Defined (1)

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

/functions.php  
  1. function wpp_linkifyYouTubeURLs($text) { 
  2. $text = preg_replace('~ 
  3. # Match non-linked youtube URL in the wild. (Rev:20130823) 
  4. https?:// # Required scheme. Either http or https. 
  5. (?:[0-9A-Z-]+\.)? # Optional subdomain. 
  6. (?: # Group host alternatives. 
  7. youtu\.be/ # Either youtu.be,  
  8. | youtube # or youtube.com or 
  9. (?:-nocookie)? # youtube-nocookie.com 
  10. \.com # followed by 
  11. \S* # Allow anything up to VIDEO_ID,  
  12. [^\w\s-] # but char before ID is non-ID char. 
  13. ) # End host alternatives. 
  14. ([\w-]{11}) # $1: VIDEO_ID is exactly 11 chars. 
  15. (?=[^\w-]|$) # Assert next char is non-ID or EOS. 
  16. (?! # Assert URL is not pre-linked. 
  17. [?=&+%\w.-]* # Allow URL (query) remainder. 
  18. (?: # Group pre-linked alternatives. 
  19. [\'"][^<>]*> # Either inside a start tag,  
  20. | </a> # or inside <a> element text contents. 
  21. ) # End recognized pre-linked alts. 
  22. ) # End negative lookahead assertion. 
  23. [?=&+%\w.-]* # Consume any URL (query) remainder. 
  24. ~ix',  
  25. '<p style="clear:both"> YouTube Video: <a href="http://www.youtube.com/watch?v=$1">YouTube.com/watch?v=$1</a> </p>',  
  26. $text); 
  27. return $text;