jetpack_instagram_embed_reversal

Embed Reversal for Instagram.

Description

((string)) jetpack_instagram_embed_reversal( $content ); 

Hooked to pre_kses, converts an embed code from Instagram.com to an oEmbeddable URL.

Returns ((string))

the filtered or the original content

Parameters (1)

0. $content
The content.

Usage

  1. if ( !function_exists( 'jetpack_instagram_embed_reversal' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/shortcodes/instagram.php'; 
  3.  
  4. // The content. 
  5. $content = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = jetpack_instagram_embed_reversal($content); 
  9.  

Defined (1)

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

/modules/shortcodes/instagram.php  
  1. function jetpack_instagram_embed_reversal( $content ) { 
  2. if ( false === stripos( $content, 'instagram.com' ) ) 
  3. return $content; 
  4.  
  5. /** Sample embed code: 
  6. <blockquote class="instagram-media" data-instgrm-captioned data-instgrm-version="2" style=" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0, 0, 0, 0.5), 0 1px 10px 0 rgba(0, 0, 0, 0.15); margin: 1px; max-width:658px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"><div style="padding:8px;"><div style=" background:#F8F8F8; line-height:0; margin-top:40px; padding-bottom:55%; padding-top:45%; text-align:center; width:100%;"><div style="position:relative;"><div style=" -webkit-animation:dkaXkpbBxI 1s ease-out infinite; animation:dkaXkpbBxI 1s ease-out infinite; background:url(data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAACwAAAAsCAMAAAApWqozAAAAGFBMVEUiIiI9PT0eHh4gIB4hIBkcHBwcHBwcHBydr+JQAAAACHRSTlMABA4YHyQsM5jtaMwAAADfSURBVDjL7ZVBEgMhCAQBAf//42xcNbpAqakcM0ftUmFAAIBE81IqBJdS3lS6zs3bIpB9WED3YYXFPmHRfT8sgyrCP1x8uEUxLMzNWElFOYCV6mHWWwMzdPEKHlhLw7NWJqkHc4uIZphavDzA2JPzUDsBZziNae2S6owH8xPmX8G7zzgKEOPUoYHvGz1TBCxMkd3kwNVbU0gKHkx+iZILf77IofhrY1nYFnB/lQPb79drWOyJVa/DAvg9B/rLB4cC+Nqgdz/TvBbBnr6GBReqn/nRmDgaQEej7WhonozjF+Y2I/fZou/qAAAAAElFTkSuQmCC); display:block; height:44px; margin:0 auto -44px; position:relative; top:-44px; width:44px;"></div><span style=" color:#c9c8cd; font-family:Arial, sans-serif; font-size:12px; font-style:normal; font-weight:bold; position:relative; top:15px;">Loading</span></div></div><p style=" font-family:Arial, sans-serif; font-size:14px; line-height:17px; margin:8px 0 0 0; padding:0 4px; word-wrap:break-word;"> Balloons</p><p style=" line-height:32px; margin-bottom:0; margin-top:8px; padding:0; text-align:center;"> <a href="https://instagram.com/p/r9vfPrmjeB/" style=" color:#c9c8cd; font-family:Arial, sans-serif; font-size:14px; font-style:normal; font-weight:normal; text-decoration:none;" target="_top"> View on Instagram</a></p></div><style>@-webkit-keyframes"dkaXkpbBxI"{ 0%{opacity:0.5;} 50%{opacity:1;} 100%{opacity:0.5;} } @keyframes"dkaXkpbBxI"{ 0%{opacity:0.5;} 50%{opacity:1;} 100%{opacity:0.5;} }</style></blockquote> 
  7. <script async defer src="https://platform.instagram.com/en_US/embeds.js"></script> 
  8. */ 
  9.  
  10. $regexes = array(); 
  11.  
  12. // new style js 
  13. $regexes[] = '#<blockquote[^>]+?class="instagram-media"[^>](.+?)>(.+?)</blockquote><script[^>]+?src="(https?:)?//platform\.instagram\.com/(.+?)/embeds\.js"></script>#ix'; 
  14.  
  15. // Let's play nice with the visual editor too. 
  16. $regexes[] = '#<blockquote(?:[^&]|&(?!gt;))+?class="instagram-media"(?:[^&]|&(?!gt;))(.+?)>(.+?)</blockquote><script(?:[^&]|&(?!gt;))+?src="(https?:)?//platform\.instagram\.com/(.+?)/embeds\.js"(?:[^&]|&(?!gt;))*+></script>#ix'; 
  17.  
  18. // old style iframe 
  19. $regexes[] = '#<iframe[^>]+?src="(?:https?:)?//instagram\.com/p/([^"\'/]++)[^"\']*?"[^>]*+>\s*?</iframe>#i'; 
  20.  
  21. // Let's play nice with the visual editor too. 
  22. $regexes[] = '#<iframe(?:[^&]|&(?!gt;))+?src="(?:https?:)?//instagram\.com/p/([^"\'/]++)[^"\']*?"(?:[^&]|&(?!gt;))*+>\s*?</iframe>#i'; 
  23.  
  24. foreach ( $regexes as $regex ) { 
  25. if ( ! preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) 
  26. continue; 
  27.  
  28. foreach ( $matches as $match ) { 
  29. if ( ! preg_match( '#(https?:)?//instagr(\.am|am\.com)/p/([^/]*)#i', $match[2], $url_matches ) ) 
  30. continue; 
  31.  
  32. // Since we support Instagram via oEmbed, we simply leave a link on a line by itself. 
  33. $replace_regex = sprintf( '#\s*%s\s*#', preg_quote( $match[0], '#' ) ); 
  34. $url = esc_url( $url_matches[0] ); 
  35.  
  36. $content = preg_replace( $replace_regex, sprintf( "\n\n%s\n\n", $url ), $content ); 
  37. /** This action is documented in modules/shortcodes/youtube.php */ 
  38. do_action( 'jetpack_embed_to_shortcode', 'instagram', $url ); 
  39.  
  40. return $content;