diff options
Diffstat (limited to 'plugins/jetpack/modules/shortcodes/ted.php')
-rw-r--r-- | plugins/jetpack/modules/shortcodes/ted.php | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/plugins/jetpack/modules/shortcodes/ted.php b/plugins/jetpack/modules/shortcodes/ted.php index b26ef1da..a6c5dabd 100644 --- a/plugins/jetpack/modules/shortcodes/ted.php +++ b/plugins/jetpack/modules/shortcodes/ted.php @@ -10,7 +10,7 @@ * [ted id="http://www.ted.com/talks/view/id/210" lang="en"] * [ted id=1539 lang=fr width=560 height=315] * - * @package Jetpack + * @package automattic/jetpack */ wp_oembed_add_provider( '!https?://(www\.)?ted.com/talks/view/id/.+!i', 'https://www.ted.com/talks/oembed.json', true ); @@ -96,3 +96,26 @@ add_shortcode( 'ted', 'shortcode_ted' ); function ted_filter_oembed_fetch_url( $provider, $url, $args ) { return add_query_arg( 'lang', $args['lang'], $provider ); } + +/** + * Filter the oembed html to set the sandbox attribute in the iframe + * + * @param string|false $cache The cached HTML result, stored in post meta. + * @param string $url The attempted embed URL. + * + * @return string|false + */ +function ted_filter_oembed_amp_iframe( $cache, $url ) { + if ( is_string( $cache ) + && strpos( $url, 'ted.com' ) + ) { + $cache = preg_replace( + '/src=[\'"].*?[\'"]/', + '$0 sandbox="allow-popups allow-scripts allow-same-origin"', + $cache + ); + } + + return $cache; +} +add_filter( 'embed_oembed_html', 'ted_filter_oembed_amp_iframe', 10, 2 ); |