Make WordPress Core

Ticket #23282: 23282.2.diff

File 23282.2.diff, 5.7 KB (added by wonderboymusic, 12 years ago)
  • wp-includes/media.php

    diff --git wp-includes/media.php wp-includes/media.php
    index 682ffbb..148ad8c 100644
    function gallery_shortcode($attr) { 
    803803}
    804804
    805805/**
     806 * The Audio shortcode.
     807 *
     808 * This implements the functionality of the Audio Shortcode for displaying
     809 * WordPress mp3s in a post.
     810 *
     811 * @since 3.6.0
     812 *
     813 * @param array $attr Attributes of the shortcode.
     814 * @return string HTML content to display audio.
     815 */
     816function wp_audio_shortcode( $attr ) {
     817        $post = get_post();
     818
     819        static $instances = 0;
     820        $instances++;
     821
     822        $audio = null;
     823
     824        extract( shortcode_atts( array( 'src' => '' ), $attr ) );
     825
     826        if ( empty( $src ) ) {
     827                $children = get_children( array(
     828                        'post_parent' => $post->ID,
     829                        'post_type' => 'attachment',
     830                        'post_mime_type' => 'audio',
     831                        'posts_per_page' => 1
     832                ) );
     833
     834                if ( empty( $children ) )
     835                        return;
     836
     837                $audio = reset( $children );
     838                $src = wp_get_attachment_url( $audio->ID );
     839                if ( empty( $src ) )
     840                        return;
     841        }
     842
     843        wp_enqueue_style( 'wp-mediaelement' );
     844        wp_enqueue_script( 'wp-mediaelement' );
     845
     846        $html = sprintf( '<audio class="%s" id="%s" src="%s" type="audio/mp3" controls="controls"></audio>',
     847                apply_filters( 'audio_shortcode_class', 'wp-audio-shortcode' ),
     848                sprintf( 'audio-%d-%d', $post->ID, $instances ),
     849                esc_url( $src )
     850        );
     851
     852        return apply_filters( 'audio_shortcode', $html, $src, $audio, $post );
     853}
     854add_shortcode( 'audio', 'wp_audio_shortcode' );
     855
     856/**
     857 * The Video shortcode.
     858 *
     859 * This implements the functionality of the Video Shortcode for displaying
     860 * WordPress mp4s in a post.
     861 *
     862 * @since 3.6.0
     863 *
     864 * @param array $attr Attributes of the shortcode.
     865 * @return string HTML content to display video.
     866 */
     867function wp_video_shortcode( $attr ) {
     868        global $content_width;
     869        $post = get_post();
     870
     871        static $instances = 0;
     872        $instances++;
     873
     874        $video = null;
     875
     876        extract( shortcode_atts( array(
     877                'src' => '',
     878                'width' => empty( $content_width ) ? 640 : $content_width,
     879                'height' => 360,
     880                'poster' => '',
     881                'webm' => '',
     882                'ogv' => '',
     883                'flash' => true
     884        ), $attr ) );
     885
     886        if ( empty( $src ) ) {
     887                $children = get_children( array(
     888                        'post_parent' => $post->ID,
     889                        'post_type' => 'attachment',
     890                        'post_mime_type' => 'video',
     891                        'posts_per_page' => 1
     892                ) );
     893
     894                if ( empty( $children ) )
     895                        return;
     896
     897                $video = reset( $children );
     898                $src = wp_get_attachment_url( $video->ID );
     899                if ( empty( $src ) )
     900                        return;
     901        }
     902
     903        wp_enqueue_style( 'wp-mediaelement' );
     904        wp_enqueue_script( 'wp-mediaelement' );
     905
     906        $atts = array(
     907                sprintf( 'class="%s"', apply_filters( 'video_shortcode_class', 'wp-video-shortcode' ) ),
     908                sprintf( 'id="video-%d-%d"', $post->ID, $instances ),
     909                sprintf( 'width="%d"', $width ),
     910                sprintf( 'height="%d"', $height ),
     911        );
     912
     913        if ( ! empty( $poster ) )
     914                $atts[] = sprintf( 'poster="%s"', esc_url( $poster ) );
     915
     916        if ( empty( $webm ) && empty( $ogv ) ) {
     917                $atts[] = sprintf( 'src="%s"', esc_url( $src ) );
     918                $atts[] = 'type="video/mp4"';
     919
     920                $html = sprintf( '<video %s controls="controls" preload="none"></video>',
     921                        join( ' ', $atts )
     922                );
     923        } else {
     924                $source = '<source type="%s" src="%s" />';
     925
     926                $html = sprintf( '<video %s controls="controls" preload="none">', join( ' ', $atts ) );
     927                $html .= sprintf( $source, 'video/mp4', $src );
     928                if ( ! empty( $webm ) )
     929                        $html .= sprintf( $source, 'video/webm', $webm );
     930                if ( ! empty( $ogv ) )
     931                        $html .= sprintf( $source, 'video/ogg', $ogv );
     932
     933                if ( $flash && 'false' !== $flash ) {
     934                        $flashsrc = '/wp-includes/js/mediaelement/flashmediaelement.swf';
     935
     936                        $html .= sprintf( '<object width="%d" height="%d" type="application/x-shockwave-flash" data="%s">',
     937                                $width,
     938                                $height,
     939                                $flashsrc
     940                        );
     941
     942                        $html .= sprintf( '<param name="movie" value="%s"/>', esc_url( $flashsrc ) );
     943                        $html .= sprintf( '<param name="flashvars" value="controls=true&amp;file=%s"/>', esc_url( $src ) );
     944                        if ( ! empty( $poster ) )
     945                                $html .= sprintf( '<img src="%s" width="%d" height="%d" />',
     946                                        esc_url( $poster ),
     947                                        $width,
     948                                        $height
     949                                );
     950                        $html .= '</object>';
     951                }
     952                $html .= '</video>';
     953        }
     954
     955        return apply_filters( 'video_shortcode', $html, $src, $video, $post );
     956}
     957add_shortcode( 'video', 'wp_video_shortcode' );
     958
     959/**
    806960 * Display previous image link that has the same post parent.
    807961 *
    808962 * @since 2.5.0
  • wp-includes/script-loader.php

    diff --git wp-includes/script-loader.php wp-includes/script-loader.php
    index 9612e72..57a9abb 100644
    function wp_default_scripts( &$scripts ) { 
    274274
    275275        $scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array('jquery'), '0.9.8', 1 );
    276276
     277        $scripts->add( 'mediaelement', "/wp-includes/js/mediaelement/mediaelement-and-player$suffix.js", array('jquery'), '2.10.1', 1 );
     278        $scripts->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement.js", array('mediaelement'), false, 1 );
     279
    277280        $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array('jquery'), false, 1 );
    278281        did_action( 'init' ) && $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
    279282                'empty' => __('Strength indicator'),
    function wp_default_styles( &$styles ) { 
    538541        $styles->add( 'media-views', "/wp-includes/css/media-views$suffix.css", array( 'buttons' ) );
    539542        $styles->add( 'buttons', "/wp-includes/css/buttons$suffix.css" );
    540543
     544        $styles->add( 'mediaelement', "/wp-includes/js/mediaelement/mediaelementplayer$suffix.css" );
     545        $styles->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement.css", array( 'mediaelement' ) );
     546
    541547        foreach ( $rtl_styles as $rtl_style ) {
    542548                $styles->add_data( $rtl_style, 'rtl', true );
    543549                if ( $suffix && ! in_array( $rtl_style, $no_suffix ) )