vimeo_shortcode

Convert a Vimeo shortcode into an embed code.

Description

(string) vimeo_shortcode( (array) $atts ); 

Returns (string)

The embed code for the Vimeo video.

Parameters (1)

0. $atts (array)
An array of shortcode attributes.

Usage

  1. if ( !function_exists( 'vimeo_shortcode' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/shortcodes/vimeo.php'; 
  3.  
  4. // An array of shortcode attributes. 
  5. $atts = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = vimeo_shortcode($atts); 
  9.  

Defined (1)

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

/modules/shortcodes/vimeo.php  
  1. function vimeo_shortcode( $atts ) { 
  2. global $content_width; 
  3.  
  4. extract( array_map( 'intval', shortcode_atts( array( 
  5. 'id' => 0,  
  6. 'width' => 400,  
  7. 'height' => 300,  
  8. 'autoplay' => 0,  
  9. 'loop' => 0,  
  10. ), $atts, 'vimeo' ) ) ); 
  11.  
  12. if ( isset( $atts[0] ) ) { 
  13.  
  14. if ( ! $id ) return "<!-- vimeoerror not a vimeo video -->"; 
  15.  
  16. // [vimeo 141358 h=500&w=350] 
  17. $params = shortcode_new_to_old_params( $atts ); // h=500&w=350 
  18. $params = str_replace( array( '&', '&' ), '&', $params ); 
  19. parse_str( $params, $args ); 
  20.  
  21. if ( isset( $args['w'] ) ) { 
  22. $width = (int) $args['w']; 
  23.  
  24. if ( ! isset( $args['h'] ) ) { 
  25. // The case where w=300 is specified without h=200, otherwise $height 
  26. // will always equal the default of 300, no matter what w was set to. 
  27. $height = round( ( $width / 640 ) * 360 ); 
  28.  
  29. if ( isset( $args['h'] ) ) { 
  30. $height = (int) $args['h']; 
  31.  
  32. if ( ! isset( $args['w'] ) ) { 
  33. $width = round( ( $height / 360 ) * 640 ); 
  34.  
  35. if ( ! $width ) { 
  36. $width = absint( $content_width ); 
  37.  
  38. if ( ! $height ) { 
  39. $height = round( ( $width / 640 ) * 360 ); 
  40.  
  41. /** 
  42. * Filter the Vimeo player width. 
  43. * @module shortcodes 
  44. * @since 3.4.0 
  45. * @param int $width Width of the Vimeo player in pixels. 
  46. */ 
  47. $width = (int) apply_filters( 'vimeo_width', $width ); 
  48.  
  49. /** 
  50. * Filter the Vimeo player height. 
  51. * @module shortcodes 
  52. * @since 3.4.0 
  53. * @param int $height Height of the Vimeo player in pixels. 
  54. */ 
  55. $height = (int) apply_filters( 'vimeo_height', $height ); 
  56.  
  57. $url = esc_url( "https://player.vimeo.com/video/$id" ); 
  58.  
  59. // $args['autoplay'] is parsed from the embedded url. 
  60. // $autoplay is parsed from shortcode arguments. 
  61. // in_array( 'autoplay', $atts ) catches the argument passed without a value. 
  62. if ( ! empty( $args['autoplay'] ) || ! empty( $autoplay ) || in_array( 'autoplay', $atts ) ) { 
  63. $url = add_query_arg( 'autoplay', 1, $url ); 
  64.  
  65. if ( ! empty( $args['loop'] ) || ! empty( $loop ) || in_array( 'loop', $atts ) ) { 
  66. $url = add_query_arg( 'loop', 1, $url ); 
  67.  
  68. $html = sprintf( '<div class="embed-vimeo" style="text-align:center;"><iframe src="%1$s" width="%2$u" height="%3$u" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>', esc_url( $url ), $width, $height ); 
  69.  
  70. /** 
  71. * Filter the Vimeo player HTML. 
  72. * @module shortcodes 
  73. * @since 1.2.3 
  74. * @param string $html Embedded Vimeo player HTML. 
  75. */ 
  76. $html = apply_filters( 'video_embed_html', $html ); 
  77.  
  78. return $html;