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. Built from https://develop.svn.wordpress.org/trunk@28652 git-svn-id: http://core.svn.wordpress.org/trunk@28470 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
324565bb17
commit
91e6a8c017
|
@ -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]) . '&hl=en&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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue