jan_dembowski

content-rickroll.php

Apr 22nd, 2012
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Rick Roll YouTube URLs
  4. Description: Exactly what it says.
  5. Author: Jan Dembowski
  6. */
  7.  
  8. add_filter( 'the_content' , 'mh_rick_roll_content' , 0 );
  9. function mh_rick_roll_content( $content ) {
  10.         /*
  11.         Replace YouTube videos with a Rickroll
  12.         http://www.youtube.com/watch?v=dQw4w9WgXcQ
  13.         */
  14.  
  15.         $mh_url_regex = "/http\:\/\/www\.youtube\.com\/watch\?v\=[a-zA-Z0-9\-]+/";
  16.         preg_match_all( $mh_url_regex , $content, $mh_matches );
  17.  
  18.         for ( $mh_count = 0; $mh_count < count( $mh_matches[0] ); $mh_count++ )
  19.         {
  20.                 $mh_old_url = $mh_matches[0][$mh_count];
  21.                 $mh_new_url = 'http://www.youtube.com/watch?v=dQw4w9WgXcQ';
  22.                 $content = str_replace( $mh_old_url , $mh_new_url , $content );
  23.         }
  24.  
  25.         return $content;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment