Advertisement
Guest User

youtube-wmode-opacity for Buddypress oEmbed

a guest
Oct 16th, 2013
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: YouTube wmode adjuster
  4. Description: This plugin will modify the YouTube oEmbed output and add some parameters.
  5. Author: Jan Dembowski
  6. Author URI: http://blog.dembowski.net/
  7. Version: 0.1
  8. */
  9.  
  10. /*
  11. From http://wordpress.org/support/topic/help-adding-wmodetransparent-to-oembeds
  12.  
  13. Example:
  14. <iframe width="625" height="352" src="http://www.youtube.com/embed/MCWJUSulnro?feature=oembed" frameborder="0" allowfullscreen></iframe>
  15.  
  16. Replace ?feature=oembed with ?wmode=transparent and add wmode="Opaque" to the end of the <iframe ...>
  17.  
  18. <iframe width="625" height="352" src="http://www.youtube.com/embed/MCWJUSulnro?wmode=transparent" frameborder="0" allowfullscreen wmode="Opaque"></iframe>
  19. */
  20.  
  21.  
  22. add_filter( 'the_content' , 'mh_youtube_wmode' , 15 );
  23. add_filter('bp_get_activity_content_body','mh_youtube_wmode');
  24.  
  25. function mh_youtube_wmode( $content ) {
  26.  
  27. // Regex to find all <ifram ... > YouTube tags
  28. $mh_youtube_regex = "/\<iframe .*youtube\.com.*><\/iframe>/";
  29.  
  30. // Populate the results into an array
  31. preg_match_all( $mh_youtube_regex , $content, $mh_matches );
  32.  
  33. // If we get any hits then put the update the results
  34. if ( $mh_matches ) {;
  35.     for ( $mh_count = 0; $mh_count < count( $mh_matches[0] ); $mh_count++ )
  36.         {
  37.         // Old YouTube iframe
  38.         $mh_old = $mh_matches[0][$mh_count];
  39.  
  40.         $mh_new = str_replace( "?feature=oembed" , "?wmode=transparent" , $mh_old );
  41.         $mh_new = preg_replace( '/\><\/iframe>$/' , ' wmode="Opaque"></iframe>' , $mh_new );
  42.  
  43.         // make the substitution
  44.         $content = str_replace( $mh_old, $mh_new , $content );
  45.         }
  46.     }
  47. return $content;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement