WordPress.org

Make WordPress Core

Ticket #28619: 28619.patch

File 28619.patch, 3.9 KB (added by Fab1en, 6 years ago)

Add filters for audio and video shortcodes

  • wp-includes/media.php

    From d5c912a79bb970ae45641f137b1670a3faad955d Mon Sep 17 00:00:00 2001
    From: Fabien Quatravaux <fabien.quatravaux@1nterval.com>
    Date: Tue, 24 Jun 2014 10:56:45 +0200
    Subject: [PATCH] [dev #28619] Add filters to tune mediaelement library
    
    ---
     wp-includes/media.php | 42 ++++++++++++++++++++++++++++++++----------
     1 file changed, 32 insertions(+), 10 deletions(-)
    
    diff --git a/wp-includes/media.php b/wp-includes/media.php
    index 974aa79..f9c0d18 100644
    a b function wp_audio_shortcode( $attr, $content = '' ) { 
    15711571                $attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
    15721572        }
    15731573
    1574         $html = '';
    1575         if ( 'mediaelement' === $library && 1 === $instances )
    1576                 $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
     1574        $html = apply_filters('wp_audio_shortcode_pre_html', '', $library, $instances);
    15771575        $html .= sprintf( '<audio %s controls="controls">', join( ' ', $attr_strings ) );
    15781576
    15791577        $fileurl = '';
    function wp_audio_shortcode( $attr, $content = '' ) { 
    15881586                }
    15891587        }
    15901588
    1591         if ( 'mediaelement' === $library )
    1592                 $html .= wp_mediaelement_fallback( $fileurl );
     1589        $html .= apply_filters('wp_audio_shortcode_inside_html', '', $library, $fileurl, $post_id);
    15931590        $html .= '</audio>';
    15941591
    15951592        /**
    function wp_audio_shortcode( $attr, $content = '' ) { 
    16071604}
    16081605add_shortcode( 'audio', 'wp_audio_shortcode' );
    16091606
     1607function wp_mediaelement_audio_shortcode_pre_html($html, $library, $instances) {
     1608    if ( 'mediaelement' === $library && 1 === $instances )
     1609                $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
     1610    return $html;
     1611}
     1612add_filter('wp_audio_shortcode_pre_html', 'wp_mediaelement_audio_shortcode_pre_html', 10, 3);
     1613
     1614function wp_mediaelement_audio_shortcode_inside_html($html, $library, $fileurl, $post_id) {
     1615        if ( 'mediaelement' === $library )
     1616                $html .= wp_mediaelement_fallback( $fileurl );
     1617        return $html;
     1618}
     1619add_filter('wp_audio_shortcode_inside_html', 'wp_mediaelement_audio_shortcode_inside_html', 10, 4);
     1620
    16101621/**
    16111622 * Return a filtered list of WP-supported video formats
    16121623 *
    function wp_video_shortcode( $attr, $content = '' ) { 
    17881799                $attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
    17891800        }
    17901801
    1791         $html = '';
    1792         if ( 'mediaelement' === $library && 1 === $instances )
    1793                 $html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
     1802        $html = apply_filters('wp_video_shortcode_pre_html', '', $library, $instances);
    17941803        $html .= sprintf( '<video %s controls="controls">', join( ' ', $attr_strings ) );
    17951804
    17961805        $fileurl = '';
    function wp_video_shortcode( $attr, $content = '' ) { 
    18171826                $html .= trim( $content );
    18181827        }
    18191828
    1820         if ( 'mediaelement' === $library )
    1821                 $html .= wp_mediaelement_fallback( $fileurl );
     1829        $html .= apply_filters('wp_video_shortcode_inside_html', '', $library, $fileurl, $post_id);
    18221830        $html .= '</video>';
    18231831
    18241832        $html = sprintf( '<div style="width: %dpx; max-width: 100%%;" class="wp-video">%s</div>', $width, $html );
    function wp_video_shortcode( $attr, $content = '' ) { 
    18381846}
    18391847add_shortcode( 'video', 'wp_video_shortcode' );
    18401848
     1849function wp_mediaelement_video_shortcode_pre_html($html, $library, $instances) {
     1850    if ( 'mediaelement' === $library && 1 === $instances )
     1851                $html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
     1852    return $html;
     1853}
     1854add_filter('wp_video_shortcode_pre_html', 'wp_mediaelement_video_shortcode_pre_html', 10, 3);
     1855
     1856function wp_mediaelement_video_shortcode_inside_html($html, $library, $fileurl, $post_id) {
     1857        if ( 'mediaelement' === $library )
     1858                $html .= wp_mediaelement_fallback( $fileurl );
     1859        return $html;
     1860}
     1861add_filter('wp_video_shortcode_inside_html', 'wp_mediaelement_video_shortcode_inside_html', 10, 4);
     1862
    18411863/**
    18421864 * Display previous image link that has the same post parent.
    18431865 *