vimeo_embed_to_shortcode

The Jetpack by WordPress.com vimeo embed to shortcode function.

Description

vimeo_embed_to_shortcode( $content ); 

Parameters (1)

0. $content
The content.

Usage

  1. if ( !function_exists( 'vimeo_embed_to_shortcode' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/shortcodes/vimeo.php'; 
  3.  
  4. // The content. 
  5. $content = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = vimeo_embed_to_shortcode($content); 
  9.  

Defined (1)

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

/modules/shortcodes/vimeo.php  
  1. function vimeo_embed_to_shortcode( $content ) { 
  2. if ( false === stripos( $content, 'player.vimeo.com/video/' ) ) 
  3. return $content; 
  4.  
  5. $regexp = '!<iframe\s+src=[\'"](https?:)?//player\.vimeo\.com/video/(\d+)[\w=&;?]*[\'"]((?:\s+\w+=[\'"][^\'"]*[\'"])*)((?:[\s\w]*))></iframe>!i'; 
  6. $regexp_ent = str_replace( '&#0*58;', '&#0*58;|�*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) ); 
  7.  
  8. foreach ( array( 'regexp', 'regexp_ent' ) as $reg ) { 
  9. if ( !preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) 
  10. continue; 
  11.  
  12. foreach ( $matches as $match ) { 
  13. $id = (int) $match[2]; 
  14.  
  15. $params = $match[3]; 
  16.  
  17. if ( 'regexp_ent' == $reg ) 
  18. $params = html_entity_decode( $params ); 
  19.  
  20. $params = wp_kses_hair( $params, array( 'http' ) ); 
  21.  
  22. $width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0; 
  23. $height = isset( $params['height'] ) ? (int) $params['height']['value'] : 0; 
  24.  
  25. $wh = ''; 
  26. if ( $width && $height ) 
  27. $wh = ' w=' . $width . ' h=' . $height; 
  28.  
  29. $shortcode = '[vimeo ' . $id . $wh . ']'; 
  30. $content = str_replace( $match[0], $shortcode, $content ); 
  31.  
  32. return $content;