shortcode_ted

The Jetpack by WordPress.com shortcode ted function.

Description

shortcode_ted( $atts, (string) $content = '' ); 

Parameters (2)

0. $atts
The atts.
1. $content — Optional. (string) => ''
The content.

Usage

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

Defined (1)

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

/modules/shortcodes/ted.php  
  1. function shortcode_ted( $atts, $content = '' ) { 
  2. global $wp_embed; 
  3.  
  4. $defaults = array( 
  5. 'id' => '',  
  6. 'width' => '',  
  7. 'height' => '',  
  8. 'lang' => 'en',  
  9. ); 
  10. $atts = shortcode_atts( $defaults, $atts, 'ted' ); 
  11.  
  12. if ( empty( $atts['id'] ) ) 
  13. return '<!-- Missing TED ID -->'; 
  14.  
  15. if ( preg_match( "#^[\d]+$#", $atts['id'], $matches ) ) 
  16. $url = 'http://ted.com/talks/view/id/' . $matches[0]; 
  17. elseif ( preg_match( "#^https?://(www\.)?ted\.com/talks/view/id/[0-9]+$#", $atts['id'], $matches ) ) 
  18. $url = $matches[0]; 
  19.  
  20. unset( $atts['id'] ); 
  21.  
  22. $args = array(); 
  23. if ( is_numeric( $atts['width'] ) ) 
  24. $args['width'] = $atts['width']; 
  25. else if ( $embed_size_w = get_option( 'embed_size_w' ) ) 
  26. $args['width'] = $embed_size_w; 
  27. else if ( ! empty( $GLOBALS['content_width'] ) ) 
  28. $args['width'] = (int)$GLOBALS['content_width']; 
  29. else 
  30. $args['width'] = 500; 
  31.  
  32. // Default to a 16x9 aspect ratio if there's no height set 
  33. if ( is_numeric( $atts['height'] ) ) 
  34. $args['height'] = $atts['height']; 
  35. else 
  36. $args['height'] = $args['width'] * 0.5625; 
  37.  
  38. if ( ! empty( $atts['lang'] ) ) { 
  39. $args['lang'] = sanitize_key( $atts['lang'] ); 
  40. $retval = $wp_embed->shortcode( $args, $url ); 
  41. return $retval;