PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 3.1.5
Jetpack – WP Security, Backup, Speed, & Growth v3.1.5
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / shortcodes / mixcloud.php

mixcloud.php in Jetpack – WP Security, Backup, Speed, & Growth 3.1.5, at modules/shortcodes/mixcloud.php

53 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Mixcloud embeds
4 *
5 * examples:
6 * [mixcloud MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/ /]
7 * [mixcloud MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/ width=640 height=480 /]
8 * [mixcloud http://www.mixcloud.com/MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/ /]
9 * [mixcloud http://www.mixcloud.com/MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/ width=640 height=480 /]
10 * [mixcloud]http://www.mixcloud.com/MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/[/mixcloud]
11 * [mixcloud]MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/[/mixcloud]
12 */
13
14 // Register oEmbed provider
15 // Example URL: http://www.mixcloud.com/oembed/?url=http://www.mixcloud.com/MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/
16 wp_oembed_add_provider('#https?://(?:www\.)?mixcloud\.com/\S*#i', 'http://www.mixcloud.com/oembed', true);
17
18 // Register mixcloud shortcode
19 add_shortcode( 'mixcloud', 'mixcloud_shortcode' );
20 function mixcloud_shortcode( $atts, $content = null ) {
21
22 if ( empty( $atts[0] ) && empty( $content ) )
23 return "<!-- mixcloud error: invalid mixcloud resource -->";
24
25 $regular_expression = "#((?<=mixcloud.com/)([A-Za-z0-9_-]+/[A-Za-z0-9_-]+))|^([A-Za-z0-9_-]+/[A-Za-z0-9_-]+)#i";
26 preg_match( $regular_expression, $content, $match );
27 if ( ! empty( $match ) ) {
28 $resource_id = trim( $match[0] );
29 } else {
30 preg_match( $regular_expression, $atts[0], $match );
31 if ( ! empty( $match ) )
32 $resource_id = trim( $match[0] );
33 }
34
35 if ( empty( $resource_id ) )
36 return "<!-- mixcloud error: invalid mixcloud resource -->";
37
38 $atts = shortcode_atts( array(
39 'width' => 300,
40 'height' => 300,
41 ), $atts );
42
43
44 // Build URL
45 $url = add_query_arg( $atts, "http://api.mixcloud.com/$resource_id/embed-html/" );
46 $head = wp_remote_head( $url );
47 if ( is_wp_error( $head ) || 200 != $head['response']['code'] )
48 return "<!-- mixcloud error: invalid mixcloud resource -->";
49
50 return sprintf( '<iframe width="%d" height="%d" scrolling="no" frameborder="no" src="%s"></iframe>', $atts['width'], $atts['height'], esc_url( $url ) );
51
52 }
53