mixcloud_shortcode

The Jetpack by WordPress.com mixcloud shortcode function.

Description

mixcloud_shortcode( $atts, (null) $content = null ); 

Parameters (2)

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

Usage

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

Defined (1)

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

/modules/shortcodes/mixcloud.php  
  1. function mixcloud_shortcode( $atts, $content = null ) { 
  2.  
  3. if ( empty( $atts[0] ) && empty( $content ) ) 
  4. return "<!-- mixclouderror invalid mixcloud resource -->"; 
  5.  
  6. $regular_expression = '#((?<=mixcloud.com/)([A-Za-z0-9%-]+/[A-Za-z0-9%-]+))|^([A-Za-z0-9%-]+/[A-Za-z0-9%-]+)#i'; 
  7. preg_match( $regular_expression, $content, $match ); 
  8. if ( ! empty( $match ) ) { 
  9. $resource_id = trim( $match[0] ); 
  10. } else { 
  11. preg_match( $regular_expression, $atts[0], $match ); 
  12. if ( ! empty( $match ) ) 
  13. $resource_id = trim( $match[0] ); 
  14.  
  15. if ( empty( $resource_id ) ) 
  16. return "<!-- mixclouderror invalid mixcloud resource -->"; 
  17.  
  18. $atts = shortcode_atts( array( 
  19. 'width' => 300,  
  20. 'height' => 300,  
  21. ), $atts, 'mixcloud' ); 
  22.  
  23.  
  24. // Build URL 
  25. $url = add_query_arg( $atts, "http://api.mixcloud.com/$resource_id/embed-html/" ); 
  26. $head = wp_remote_head( $url ); 
  27. if ( is_wp_error( $head ) || 200 != $head['response']['code'] ) 
  28. return "<!-- mixclouderror invalid mixcloud resource -->"; 
  29.  
  30. return sprintf( '<iframe width="%d" height="%d" scrolling="no" frameborder="no" src="%s"></iframe>', $atts['width'], $atts['height'], esc_url( $url ) ); 
  31.