Use the embed_maybe_make_link filter to test WP_Embed::autoembed().

See #33106.

git-svn-id: https://develop.svn.wordpress.org/trunk@33470 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2015-07-29 00:01:22 +00:00
parent 4f814ec9ae
commit 35acd9abf8
2 changed files with 7 additions and 13 deletions

View File

@ -129,12 +129,6 @@ class WP_Embed {
* `->maybe_make_link()` can return false on failure. * `->maybe_make_link()` can return false on failure.
*/ */
public function shortcode( $attr, $url = '' ) { public function shortcode( $attr, $url = '' ) {
// This filter can be used to output custom HTML instead of allowing oEmbed to run.
$custom = apply_filters( 'wp_embed_shortcode_custom', false, $attr, $url );
if ( false !== $custom ) {
return $custom;
}
$post = get_post(); $post = get_post();
if ( empty( $url ) && ! empty( $attr['src'] ) ) { if ( empty( $url ) && ! empty( $attr['src'] ) ) {

View File

@ -655,11 +655,11 @@ EOF;
/** /**
* @ticket 33016 * @ticket 33016
*/ */
function filter_wp_embed_shortcode_custom( $custom, $attr, $url ) { function filter_wp_embed_shortcode_custom( $content, $url ) {
if ( 'https://www.example.com/?video=1' == $url ) { if ( 'https://www.example.com/?video=1' == $url ) {
$custom = "<iframe src='$url'></iframe>"; $content = '@embed URL was replaced@';
} }
return $custom; return $content;
} }
/** /**
@ -667,14 +667,14 @@ EOF;
*/ */
function test_oembed_explicit_media_link() { function test_oembed_explicit_media_link() {
global $wp_embed; global $wp_embed;
add_filter( 'wp_embed_shortcode_custom', array( $this, 'filter_wp_embed_shortcode_custom' ), 10, 3 ); add_filter( 'embed_maybe_make_link', array( $this, 'filter_wp_embed_shortcode_custom' ), 10, 2 );
$content = <<<EOF $content = <<<EOF
https://www.example.com/?video=1 https://www.example.com/?video=1
EOF; EOF;
$expected = <<<EOF $expected = <<<EOF
<iframe src='https://www.example.com/?video=1'></iframe> @embed URL was replaced@
EOF; EOF;
$result = $wp_embed->autoembed( $content ); $result = $wp_embed->autoembed( $content );
@ -686,7 +686,7 @@ EOF;
_my_function('data'); _my_function('data');
myvar = 'Hello world myvar = 'Hello world
https://www.example.com/?video=1 https://www.example.com/?video=1
don't break this'; do not break this';
// ]]> // ]]>
</script> </script>
EOF; EOF;
@ -694,6 +694,6 @@ EOF;
$result = $wp_embed->autoembed( $content ); $result = $wp_embed->autoembed( $content );
$this->assertEquals( $content, $result ); $this->assertEquals( $content, $result );
remove_filter( 'wp_embed_shortcode_custom', array( $this, 'filter_wp_embed_shortcode_custom' ), 10 ); remove_filter( 'embed_maybe_make_link', array( $this, 'filter_wp_embed_shortcode_custom' ), 10 );
} }
} }