| @@ -12,8 +12,12 @@ | ||
| 12 | 12 | * |
| 13 | 13 | * @package automattic/jetpack |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 17 | + exit( 0 ); | |
| 18 | +} | |
| 19 | + | |
| 16 | 20 | wp_oembed_add_provider( '!https?://(www\.)?ted.com/talks/view/id/.+!i', 'https://www.ted.com/talks/oembed.json', true ); |
| 17 | 21 | wp_oembed_add_provider( '!https?://(www\.)?ted.com/talks/[a-zA-Z\-\_]+\.html!i', 'https://www.ted.com/talks/oembed.json', true ); |
| 18 | 22 | |
| 19 | 23 | /** |
| @@ -105,11 +109,25 @@ | ||
| 105 | 109 | * |
| 106 | 110 | * @return string|false |
| 107 | 111 | */ |
| 108 | 112 | function ted_filter_oembed_amp_iframe( $cache, $url ) { |
| 109 | - if ( is_string( $cache ) | |
| 110 | - && strpos( $url, 'ted.com' ) | |
| 111 | - ) { | |
| 113 | + if ( ! is_string( $cache ) ) { | |
| 114 | + return $cache; | |
| 115 | + } | |
| 116 | + | |
| 117 | + $host = wp_parse_url( $url, PHP_URL_HOST ); | |
| 118 | + if ( ! $host ) { | |
| 119 | + return $cache; | |
| 120 | + } | |
| 121 | + | |
| 122 | + $allowed_hosts = array( | |
| 123 | + 'ted.com', | |
| 124 | + 'www.ted.com', | |
| 125 | + 'embed.ted.com', | |
| 126 | + ); | |
| 127 | + | |
| 128 | + $host = strtolower( $host ); | |
| 129 | + if ( in_array( $host, $allowed_hosts, true ) ) { | |
| 112 | 130 | $cache = preg_replace( |
| 113 | 131 | '/src=[\'"].*?[\'"]/', |
| 114 | 132 | '$0 sandbox="allow-popups allow-scripts allow-same-origin"', |
| 115 | 133 | $cache |