jetpack_responsive_videos_maybe_wrap_oembed

Check if oEmbed is a `$video_patterns` provider video before wrapping.

Description

(string) jetpack_responsive_videos_maybe_wrap_oembed( $html, $url ); 

Returns (string)

Parameters (2)

0. $html
The html.
1. $url
The url.

Usage

  1. if ( !function_exists( 'jetpack_responsive_videos_maybe_wrap_oembed' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/theme-tools/responsive-videos.php'; 
  3.  
  4. // The html. 
  5. $html = null; 
  6.  
  7. // The url. 
  8. $url = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = jetpack_responsive_videos_maybe_wrap_oembed($html, $url); 
  12.  

Defined (1)

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

/modules/theme-tools/responsive-videos.php  
  1. function jetpack_responsive_videos_maybe_wrap_oembed( $html, $url ) { 
  2. if ( empty( $html ) || ! is_string( $html ) || ! $url ) { 
  3. return $html; 
  4.  
  5. $jetpack_video_wrapper = '<div class="jetpack-video-wrapper">'; 
  6.  
  7. $already_wrapped = strpos( $html, $jetpack_video_wrapper ); 
  8.  
  9. // If the oEmbed has already been wrapped, return the html. 
  10. if ( false !== $already_wrapped ) { 
  11. return $html; 
  12.  
  13. /** 
  14. * oEmbed Video Providers. 
  15. * A whitelist of oEmbed video provider Regex patterns to check against before wrapping the output. 
  16. * @module theme-tools 
  17. * @since 3.8.0 
  18. * @param array $video_patterns oEmbed video provider Regex patterns. 
  19. */ 
  20. $video_patterns = apply_filters( 'jetpack_responsive_videos_oembed_videos', array( 
  21. 'https?://((m|www)\.)?youtube\.com/watch',  
  22. 'https?://((m|www)\.)?youtube\.com/playlist',  
  23. 'https?://youtu\.be/',  
  24. 'https?://(.+\.)?vimeo\.com/',  
  25. 'https?://(www\.)?dailymotion\.com/',  
  26. 'https?://dai.ly/',  
  27. 'https?://(www\.)?hulu\.com/watch/',  
  28. 'https?://wordpress.tv/',  
  29. 'https?://(www\.)?funnyordie\.com/videos/',  
  30. 'https?://vine.co/v/',  
  31. 'https?://(www\.)?collegehumor\.com/video/',  
  32. 'https?://(www\.|embed\.)?ted\.com/talks/' 
  33. ) ); 
  34.  
  35. // Merge patterns to run in a single preg_match call. 
  36. $video_patterns = '(' . implode( '|', $video_patterns ) . ')'; 
  37.  
  38. $is_video = preg_match( $video_patterns, $url ); 
  39.  
  40. // If the oEmbed is a video, wrap it in the responsive wrapper. 
  41. if ( false === $already_wrapped && 1 === $is_video ) { 
  42.  
  43. return $html;