diff --git a/wp-includes/media.php b/wp-includes/media.php index 43b5aab4f9..8a79f8f98e 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -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', '', $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. *