Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. <?php
  2. function wpdevhq_get_video(){
  3. global $wpdevhq_videos;
  4. $post_id = get_the_ID();
  5.  
  6. if( empty( $wpdevhq_videos ) ) $wpdevhq_videos = array();
  7. if( isset($wpdevhq_videos[$post_id]) ) return $wpdevhq_videos[$post_id];
  8.  
  9. $content = get_the_content();
  10. $content = apply_filters( 'the_content', $content );
  11. $content = str_replace( ']]>', ']]>', $content );
  12. $content = trim($content);
  13.  
  14. // Is the first line a video?
  15. list($line, $content) = explode("\n", $content, 2);
  16.  
  17. if ( preg_match('/\<\s*(iframe|object|embed)/i', $line) ) {
  18. $wpdevhq_videos[$post_id] = strip_tags($line, '<iframe><object><embed>');
  19. }
  20. else {
  21. $wpdevhq_videos[$post_id] = false;
  22. }
  23.  
  24. return $wpdevhq_videos[$post_id];
  25. }
  26.  
  27. /**
  28. * Removes the video from the page
  29. *
  30. * @param $content
  31. *
  32. * @return mixed
  33. */
  34. function wpdevhq_filter_video($content){
  35. list($line, $rest) = explode("\n", $content, 2);
  36. if ( preg_match('/\<\s*(iframe|object|embed)/i', $line) ) return $rest;
  37. else return $content;
  38. }
  39.  
  40. /**
  41. * You can then return the extracted video via
  42. */
  43. echo wpdevhq_get_video()
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement