Make WordPress Core

Changeset 24789


Ignore:
Timestamp:
07/24/2013 05:52:49 AM (11 years ago)
Author:
markjaquith
Message:

Fix some sizing issues with video embeds, and improve video/audio embed shortcode flexibility.

  • loop, autoplay, and preload are now available via the shortcode. Use them non-annoyingly, please!
  • Attributes that pass through the filters are now proper key/value pairs, not an array of key="value" strings.
  • preload defaults to metadata for videos. This fixes the vertical video preview and Safari ogv/webm playback issues.
  • Wrap a div around video embeds to combat a ME.js issue with responsive width=100% themes. Props kovshenin.

Fixes #24134, #24798.

File:
1 edited

Legend:

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

    r24777 r24789  
    857857
    858858    $default_types = wp_get_audio_extensions();
    859     $defaults_atts = array( 'src' => '' );
     859    $defaults_atts = array(
     860        'src'      => '',
     861        'loop'     => '',
     862        'autoplay' => '',
     863        'preload' => 'none'
     864    );
    860865    foreach ( $default_types as $type )
    861866        $defaults_atts[$type] = '';
     
    901906
    902907    $atts = array(
    903         sprintf( 'class="%s"', apply_filters( 'wp_audio_shortcode_class', 'wp-audio-shortcode' ) ),
    904         sprintf( 'id="audio-%d-%d"', $post_id, $instances ),
     908        'class'    => apply_filters( 'wp_audio_shortcode_class', 'wp-audio-shortcode' ),
     909        'id'       => sprintf( 'audio-%d-%d', $post_id, $instances ),
     910        'loop'     => $loop,
     911        'autoplay' => $autoplay,
     912        'preload'  => $preload,
    905913    );
    906914
    907     $html = sprintf( '<audio %s controls="controls" preload="none">', join( ' ', $atts ) );
     915    // These ones should just be omitted altogether if they are blank
     916    foreach ( array( 'loop', 'autoplay', 'preload' ) as $a ) {
     917        if ( empty( $atts[$a] ) )
     918            unset( $atts[$a] );
     919    }
     920
     921    $attr_strings = [];
     922    foreach ( $atts as $k => $v ) {
     923        $attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
     924    }
     925
     926    $html = sprintf( '<audio %s controls="controls">', join( ' ', $attr_strings ) );
    908927
    909928    $fileurl = '';
     
    958977    $default_types = wp_get_video_extensions();
    959978    $defaults_atts = array(
    960         'src' => '',
    961         'poster' => '',
    962         'height' => 360,
    963         'width' => empty( $content_width ) ? 640 : $content_width,
     979        'src'      => '',
     980        'poster'   => '',
     981        'loop'     => '',
     982        'autoplay' => '',
     983        'preload'  => 'metadata',
     984        'height'   => 360,
     985        'width'    => empty( $content_width ) ? 640 : $content_width,
    964986    );
    965987
     
    10191041
    10201042    $atts = array(
    1021         sprintf( 'class="%s"', apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ) ),
    1022         sprintf( 'id="video-%d-%d"', $post_id, $instances ),
    1023         sprintf( 'width="%d"', $width ),
    1024         sprintf( 'height="%d"', $height ),
     1043        'class'    => apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ),
     1044        'id'       => sprintf( 'video-%d-%d', $post_id, $instances ),
     1045        'width'    => absint( $width ),
     1046        'height'   => absint( $height ),
     1047        'poster'   => esc_url( $poster ),
     1048        'loop'     => $loop,
     1049        'autoplay' => $autoplay,
     1050        'preload'  => $preload,
    10251051    );
    10261052
    1027     if ( ! empty( $poster ) )
    1028         $atts[] = sprintf( 'poster="%s"', esc_url( $poster ) );
    1029 
    1030     $html = sprintf( '<video %s controls="controls" preload="none">', join( ' ', $atts ) );
     1053    // These ones should just be omitted altogether if they are blank
     1054    foreach ( array( 'poster', 'loop', 'autoplay', 'preload' ) as $a ) {
     1055        if ( empty( $atts[$a] ) )
     1056            unset( $atts[$a] );
     1057    }
     1058
     1059    $attr_strings = [];
     1060    foreach ( $atts as $k => $v ) {
     1061        $attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
     1062    }
     1063
     1064    $html = sprintf( '<video %s controls="controls">', join( ' ', $attr_strings ) );
    10311065
    10321066    $fileurl = '';
     
    10471081    $html .= '</video>';
    10481082
     1083    $html = sprintf( '<div style="width: %dpx; max-width: 100%%;">%s</div>', $width, $html );
    10491084    return apply_filters( 'wp_video_shortcode', $html, $atts, $video, $post_id );
    10501085}
Note: See TracChangeset for help on using the changeset viewer.