WordPress.org

Make WordPress Core

Changeset 28652


Ignore:
Timestamp:
06/02/2014 01:21:13 AM (5 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r28584 r28652  
    21852185    }
    21862186
     2187    wp_embed_register_handler( 'youtube_embed_url', '#https?://(www.)?youtube\.com/embed/([^/]+)#i', 'wp_embed_handler_youtube' );
     2188
    21872189    wp_embed_register_handler( 'googlevideo', '#http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)#i', 'wp_embed_handler_googlevideo' );
    21882190
     
    22392241     */
    22402242    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 );
     2243}
     2244
     2245/**
     2246 * The YouTube embed handler callback. Catches URLs that can be parsed but aren't supported by oEmbed.
     2247 *
     2248 * @since 4.0.0
     2249 *
     2250 * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
     2251 * @param array $attr Embed attributes.
     2252 * @param string $url The original URL that was matched by the regex.
     2253 * @param array $rawattr The original unmodified attributes.
     2254 * @return string The embed HTML.
     2255 */
     2256function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) {
     2257    global $wp_embed;
     2258    $embed = $wp_embed->autoembed( "https://youtube.com/watch?v={$matches[2]}" );
     2259    /**
     2260     * Filter the YoutTube embed output.
     2261     *
     2262     * @since 4.0.0
     2263     *
     2264     * @param string $embed   YouTube embed output.
     2265     * @param array  $attr    An array of embed attributes.
     2266     * @param string $url     The original URL that was matched by the regex.
     2267     * @param array  $rawattr The original unmodified attributes.
     2268     */
     2269    return apply_filters( 'wp_embed_handler_youtube', $embed, $attr, $url, $rawattr );
    22412270}
    22422271
Note: See TracChangeset for help on using the changeset viewer.