diff options
Diffstat (limited to 'plugins/jetpack/modules/shortcodes/mixcloud.php')
-rw-r--r-- | plugins/jetpack/modules/shortcodes/mixcloud.php | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/plugins/jetpack/modules/shortcodes/mixcloud.php b/plugins/jetpack/modules/shortcodes/mixcloud.php index 4a016d5f..49dd20d1 100644 --- a/plugins/jetpack/modules/shortcodes/mixcloud.php +++ b/plugins/jetpack/modules/shortcodes/mixcloud.php @@ -11,7 +11,7 @@ * [mixcloud]MalibuRum/play-6-kissy-sellouts-winter-sun-house-party-mix/[/mixcloud] * [mixcloud http://www.mixcloud.com/mat/playlists/classics/ width=660 height=208 hide_cover=1 hide_tracklist=1] * - * @package Jetpack + * @package automattic/jetpack */ /* @@ -79,6 +79,28 @@ function mixcloud_shortcode( $atts, $content = null ) { $response_body = json_decode( $mixcloud_response['body'] ); - return $response_body->html; + $html = $response_body->html; + + preg_match( '/sandbox="([^"]*)"/', $html, $matches ); + + if ( empty( $matches ) ) { // MixCloud doesn't use sandbox attribute. + $html = preg_replace( '/>/', ' sandbox="allow-popups allow-scripts allow-same-origin allow-presentation">', $html, 1 ); + } else { // MixCloud uses sandbox attribute. + + $allowed_values = array(); + // Here we make sure that these string are not repeated in the sandbox attribute. + $attrs = array( 'allow-popups', 'allow-scripts', 'allow-same-origin', 'allow-presentation' ); + foreach ( $attrs as $attr ) { + if ( false === strpos( $matches[1], $attr ) ) { + $allowed_values[] = $attr; + } + } + + $sandbox_value = $matches[1] . ' ' . implode( ' ', $allowed_values ); + + $html = preg_replace( '/sandbox="([^"]*)"/', "sandbox=\"$sandbox_value\"", $html ); + } + + return $html; } add_shortcode( 'mixcloud', 'mixcloud_shortcode' ); |