Embeds: Fix support for embedding in non-WordPress sites.

This moves the last of the iframe message code from PHP to JavaScript, so it can be included in any site, without needing to rely on any of WordPress' internal behaviour.

Props swissspidy.

Fixes #34451.



git-svn-id: https://develop.svn.wordpress.org/trunk@35577 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2015-11-09 00:07:03 +00:00
parent 80975befb8
commit 6b9ba5893f
4 changed files with 63 additions and 20 deletions

View File

@@ -28,7 +28,7 @@ class Tests_Filter_oEmbed_Result extends WP_UnitTestCase {
$html = '<div><iframe></iframe><iframe></iframe><p></p></div>';
$actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' );
$this->assertEquals( '<iframe sandbox="allow-scripts" security="restricted"></iframe>', $actual );
$this->assertEquals( '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"></iframe>', $actual );
}
function test_filter_oembed_result_with_newlines() {
@@ -41,7 +41,7 @@ EOD;
$actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' );
$this->assertEquals( '<iframe sandbox="allow-scripts" security="restricted"></iframe>', $actual );
$this->assertEquals( '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"></iframe>', $actual );
}
function test_filter_oembed_result_without_iframe() {
@@ -83,13 +83,23 @@ EOD;
$html = '<blockquote></blockquote><iframe></iframe>';
$actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' );
$this->assertEquals( '<blockquote></blockquote><iframe sandbox="allow-scripts" security="restricted" style="display:none;"></iframe>', $actual );
$this->assertEquals( '<blockquote class="wp-embedded-content"></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="display:none;"></iframe>', $actual );
}
function test_filter_oembed_result_allowed_html() {
$html = '<blockquote><strong><a href="" target=""></a></strong></blockquote><iframe></iframe>';
$html = '<blockquote class="foo" id="bar"><strong><a href="" target=""></a></strong></blockquote><iframe></iframe>';
$actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' );
$this->assertEquals( '<blockquote><a href=""></a></blockquote><iframe sandbox="allow-scripts" security="restricted" style="display:none;"></iframe>', $actual );
$this->assertEquals( '<blockquote class="wp-embedded-content"><a href=""></a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="display:none;"></iframe>', $actual );
}
/**
* @group feed
*/
function test_filter_feed_content() {
$html = '<blockquote></blockquote><iframe></iframe>';
$actual = _oembed_filter_feed_content( wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' ) );
$this->assertEquals( '<blockquote class="wp-embedded-content"></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"></iframe>', $actual );
}
}