Because of YouTube's overwhelming dominance in the online video space, we should help our users who paste bad URLs when possible. It is easy to fix `http://youtube.com/embed/acb1233` URLs by turning them into `http://youtube.com/watch?v=abc1233` embeds using an embed handler (we already have one to fix Google Video embeds).

We should avoid doing this in almost every other case, but it's YouTube, and it's an easy error for a novice to make.

Fixes #24660.


git-svn-id: https://develop.svn.wordpress.org/trunk@28652 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-06-02 01:21:13 +00:00
parent 9953e4ddaf
commit 6a9c55cd9f
1 changed files with 29 additions and 0 deletions

View File

@ -2184,6 +2184,8 @@ function wp_maybe_load_embeds() {
return;
}
wp_embed_register_handler( 'youtube_embed_url', '#https?://(www.)?youtube\.com/embed/([^/]+)#i', 'wp_embed_handler_youtube' );
wp_embed_register_handler( 'googlevideo', '#http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)#i', 'wp_embed_handler_googlevideo' );
/**
@ -2240,6 +2242,33 @@ function wp_embed_handler_googlevideo( $matches, $attr, $url, $rawattr ) {
return apply_filters( 'embed_googlevideo', '<embed type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docid=' . esc_attr($matches[2]) . '&amp;hl=en&amp;fs=true" style="width:' . esc_attr($width) . 'px;height:' . esc_attr($height) . 'px" allowFullScreen="true" allowScriptAccess="always" />', $matches, $attr, $url, $rawattr );
}
/**
* The YouTube embed handler callback. Catches URLs that can be parsed but aren't supported by oEmbed.
*
* @since 4.0.0
*
* @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
* @param array $attr Embed attributes.
* @param string $url The original URL that was matched by the regex.
* @param array $rawattr The original unmodified attributes.
* @return string The embed HTML.
*/
function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) {
global $wp_embed;
$embed = $wp_embed->autoembed( "https://youtube.com/watch?v={$matches[2]}" );
/**
* Filter the YoutTube embed output.
*
* @since 4.0.0
*
* @param string $embed YouTube embed output.
* @param array $attr An array of embed attributes.
* @param string $url The original URL that was matched by the regex.
* @param array $rawattr The original unmodified attributes.
*/
return apply_filters( 'wp_embed_handler_youtube', $embed, $attr, $url, $rawattr );
}
/**
* Audio embed handler callback.
*