WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/31/2014 06:58:25 PM (7 years ago)
Author:
wonderboymusic
Message:

Let the video shortcode accept a YouTube URL as the value of its src attribute, as MediaElement.js supports Chromeless YouTube videos by using a pseudo-mime-type video/youtube.

HTTP and HTTPS www, non-www, and short url fronts are supported:
http://www.youtube.com/watch
https://www.youtube.com/watch
http://youtube.com/watch
https://youtube.com/watch
http://youtu.be
https://youtu.be

Fixes #24764.

File:
1 edited

Legend:

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

    r27051 r27063  
    11481148    $width = $w;
    11491149
     1150    $yt_pattern = '#^https?://(:?www\.)?(:?youtube\.com/watch|youtu\.be/)#';
     1151
    11501152    $primary = false;
    11511153    if ( ! empty( $src ) ) {
    1152         $type = wp_check_filetype( $src, wp_get_mime_types() );
    1153         if ( ! in_array( strtolower( $type['ext'] ), $default_types ) )
    1154             return sprintf( '<a class="wp-embedded-video" href="%s">%s</a>', esc_url( $src ), esc_html( $src ) );
     1154        if ( ! preg_match( $yt_pattern, $src ) ) {
     1155            $type = wp_check_filetype( $src, wp_get_mime_types() );
     1156            if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) {
     1157                return sprintf( '<a class="wp-embedded-video" href="%s">%s</a>', esc_url( $src ), esc_html( $src ) );
     1158            }
     1159        }
    11551160        $primary = true;
    11561161        array_unshift( $default_types, 'src' );
     
    12171222            if ( empty( $fileurl ) )
    12181223                $fileurl = $$fallback;
    1219             $type = wp_check_filetype( $$fallback, wp_get_mime_types() );
    1220             // m4v sometimes shows up as video/mpeg which collides with mp4
    1221             if ( 'm4v' === $type['ext'] )
    1222                 $type['type'] = 'video/m4v';
     1224
     1225            if ( 'src' === $fallback && preg_match( $yt_pattern, $src ) ) {
     1226                $type = array( 'type' => 'video/youtube' );
     1227            } else {
     1228                $type = wp_check_filetype( $$fallback, wp_get_mime_types() );
     1229                // m4v sometimes shows up as video/mpeg which collides with mp4
     1230                if ( 'm4v' === $type['ext'] )
     1231                    $type['type'] = 'video/m4v';
     1232            }
    12231233            $html .= sprintf( $source, $type['type'], esc_url( $$fallback ) );
    12241234        }
Note: See TracChangeset for help on using the changeset viewer.