soundcloud_shortcode

SoundCloud shortcode handler.

Description

({string}) soundcloud_shortcode( ({string|array}) $atts, (null) $content = null ); 

Returns ({string})

Widget embed code HTML

Parameters (2)

0. $atts ({string|array})
The attributes passed to the shortcode like [soundcloud attr1="value" /]. Is an empty string when no arguments are given.
1. $content — Optional. (null) => null
The content between non-self closing [soundcloud]*[/soundcloud] tags.

Usage

  1. if ( !function_exists( 'soundcloud_shortcode' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/shortcodes/soundcloud.php'; 
  3.  
  4. // The attributes passed to the shortcode like [soundcloud attr1="value" /]. 
  5. // Is an empty string when no arguments are given. 
  6. $atts = null; 
  7.  
  8. // The content between non-self closing [soundcloud]*[/soundcloud] tags. 
  9. $content = null; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = soundcloud_shortcode($atts, $content); 
  13.  

Defined (1)

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

/modules/shortcodes/soundcloud.php  
  1. function soundcloud_shortcode( $atts, $content = null ) { 
  2.  
  3. // Custom shortcode options 
  4. $shortcode_options = array_merge( array('url' => trim( $content ) ), is_array( $atts ) ? $atts : array() ); 
  5.  
  6. // Turn shortcode option "param" (param=value¶m2=value) into array 
  7. $shortcode_params = array(); 
  8. if ( isset( $shortcode_options['params'] ) ) { 
  9. parse_str( html_entity_decode( $shortcode_options['params'] ), $shortcode_params ); 
  10. $shortcode_options['params'] = $shortcode_params; 
  11.  
  12. $player_type = soundcloud_get_option( 'player_type', 'visual' ); 
  13. $isIframe = $player_type !== 'flash'; 
  14. $isVisual = ! $player_type || $player_type === 'visual' || $shortcode_options['visual']; 
  15.  
  16. // User preference options 
  17. $plugin_options = array_filter(array( 
  18. 'iframe' => $isIframe,  
  19. 'width' => soundcloud_get_option( 'player_width' ),  
  20. 'height' => soundcloud_url_has_tracklist( $shortcode_options['url'] ) ? soundcloud_get_option( 'player_height_multi' ) : soundcloud_get_option( 'player_height' ),  
  21. 'params' => array_filter( array( 
  22. 'auto_play' => soundcloud_get_option( 'auto_play' ),  
  23. 'show_comments' => soundcloud_get_option( 'show_comments' ),  
  24. 'color' => soundcloud_get_option( 'color' ),  
  25. 'visual' => ( $isVisual ? 'true' : 'false' ) 
  26. )),  
  27. )); 
  28.  
  29. // Needs to be an array 
  30. if ( ! isset( $plugin_options['params'] ) ) { 
  31. $plugin_options['params'] = array(); 
  32.  
  33. // plugin options < shortcode options 
  34. $options = array_merge( 
  35. $plugin_options,  
  36. $shortcode_options 
  37. ); 
  38.  
  39. // plugin params < shortcode params 
  40. $options['params'] = array_merge( 
  41. $plugin_options['params'],  
  42. $shortcode_options['params'] 
  43. ); 
  44.  
  45. // The "url" option is required 
  46. if ( ! isset( $options['url'] ) ) { 
  47. return ''; 
  48. } else { 
  49. $options['url'] = trim( $options['url'] ); 
  50.  
  51. // Both "width" and "height" need to be integers 
  52. if (isset( $options['width'] ) && ! preg_match( '/^(\d+)(%)?$/', $options['width'] ) ) { 
  53. // set to 0 so oEmbed will use the default 100% and WordPress themes will leave it alone 
  54. $options['width'] = 0; 
  55. if ( isset( $options['height'] ) && ! preg_match( '/^(\d+)(%)?$/', $options['height'] ) ) { 
  56. unset( $options['height'] ); 
  57.  
  58. // The "iframe" option must be true to load the iframe widget 
  59. $iframe = soundcloud_booleanize( $options['iframe'] ); 
  60.  
  61. // Remove visual parameter from Flash widget, when it's false because that's the default, or when displaying the smallest player 
  62. if ( $options['params']['visual'] && ( ! $iframe || ! soundcloud_booleanize( $options['params']['visual'] ) || ( isset( $options['height'] ) && '20' == $options['height'] ) ) ) { 
  63. unset( $options['params']['visual'] ); 
  64.  
  65. // Merge in "url" value 
  66. $options['params'] = array_merge( array( 
  67. 'url' => $options['url'] 
  68. ), $options['params'] ); 
  69.  
  70. // Return html embed code 
  71. if ( $iframe ) { 
  72. return soundcloud_iframe_widget( $options ); 
  73. } else { 
  74. return soundcloud_flash_widget( $options );