Advertisement
marstheme

Untitled

Feb 11th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. if( ! function_exists( 'videotube_instagram_aspect_ratio' ) ){
  2.     /**
  3.      * @param unknown_type $aspect_ratio
  4.      * @return unknown|string
  5.      */
  6.     function videotube_instagram_aspect_ratio( $aspect_ratio ) {
  7.         $url = $host = '';
  8.         // Get the object from post meta.
  9.         $object = get_post_meta( get_the_ID(), 'video_url', true );
  10.        
  11.         if( empty( $object ) ){
  12.             return $aspect_ratio;
  13.         }
  14.        
  15.         $url = parse_url( $object );
  16.        
  17.         if( isset( $url['host'] ) && ! empty( $url['host'] ) ){
  18.             $host = preg_replace('/^www\./', '', $url['host'] );
  19.         }
  20.        
  21.         if( isset( $host ) && ! empty( $host ) ){
  22.             if( in_array( $host , array( 'instagram.com', 'twitter.com' ) ) ){
  23.                 $aspect_ratio = 'embed-responsive-' . esc_attr( $host );
  24.             }
  25.         }
  26.  
  27.         if ( preg_match('/twitter.com/', $object ) ){
  28.             $aspect_ratio = 'embed-responsive-twitter';
  29.         }
  30.        
  31.         return $aspect_ratio;
  32.     }
  33.     add_filter( 'aspect_ratio' , 'videotube_instagram_aspect_ratio', 100, 1 );
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement