Make WordPress Core

Ticket #28619: 28619.2.patch

File 28619.2.patch, 5.6 KB (added by Fab1en, 10 years ago)

Add filters (with documentation) to tune mediaelement library

  • wp-includes/media.php

    From c6ddc2f12fa98399a9d947782bb2ddd8f7e87d49 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 | 92 +++++++++++++++++++++++++++++++++++++++++++++------
     1 file changed, 82 insertions(+), 10 deletions(-)
    
    diff --git a/wp-includes/media.php b/wp-includes/media.php
    index 974aa79..7e61b30 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        /**
     1575         * Adds HTML before the audio shortcode output.
     1576         *
     1577         * Give the possibility to insert some HTML code before the <audio> tag
     1578         * generated by an audio shortcode.
     1579         *
     1580         * @since 4.0.0
     1581         *
     1582         * @param string $html      The HTML snippet to insert before the <audio> tag.
     1583         * @param string $library   Media library used for the audio shortcode.
     1584         * @param int    $instances Unique numeric ID of this audio shortcode instance.
     1585         */
     1586        $html = apply_filters('wp_audio_shortcode_pre_html', '', $library, $instances);
    15771587        $html .= sprintf( '<audio %s controls="controls">', join( ' ', $attr_strings ) );
    15781588
    15791589        $fileurl = '';
    function wp_audio_shortcode( $attr, $content = '' ) { 
    15881598                }
    15891599        }
    15901600
    1591         if ( 'mediaelement' === $library )
    1592                 $html .= wp_mediaelement_fallback( $fileurl );
     1601        /**
     1602         * Adds HTML inside the audio shortcode output.
     1603         *
     1604         * Give the possibility to insert some HTML code inside the <audio> tag
     1605         * generated by an audio shortcode.
     1606         *
     1607         * @since 4.0.0
     1608         *
     1609         * @param string $html    The HTML snippet to append into the <audio> tag.
     1610         * @param string $library Media library used for the audio shortcode.
     1611         * @param string $fileurl The URL of the audio file.
     1612         * @param int    $post_id Post ID.
     1613         */
     1614        $html .= apply_filters('wp_audio_shortcode_inside_html', '', $library, $fileurl, $post_id);
    15931615        $html .= '</audio>';
    15941616
    15951617        /**
    function wp_audio_shortcode( $attr, $content = '' ) { 
    16071629}
    16081630add_shortcode( 'audio', 'wp_audio_shortcode' );
    16091631
     1632function wp_mediaelement_audio_shortcode_pre_html($html, $library, $instances) {
     1633    if ( 'mediaelement' === $library && 1 === $instances )
     1634                $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
     1635    return $html;
     1636}
     1637add_filter('wp_audio_shortcode_pre_html', 'wp_mediaelement_audio_shortcode_pre_html', 10, 3);
     1638
     1639function wp_mediaelement_audio_shortcode_inside_html($html, $library, $fileurl, $post_id) {
     1640        if ( 'mediaelement' === $library )
     1641                $html .= wp_mediaelement_fallback( $fileurl );
     1642        return $html;
     1643}
     1644add_filter('wp_audio_shortcode_inside_html', 'wp_mediaelement_audio_shortcode_inside_html', 10, 4);
     1645
    16101646/**
    16111647 * Return a filtered list of WP-supported video formats
    16121648 *
    function wp_video_shortcode( $attr, $content = '' ) { 
    17881824                $attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
    17891825        }
    17901826
    1791         $html = '';
    1792         if ( 'mediaelement' === $library && 1 === $instances )
    1793                 $html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
     1827        /**
     1828         * Adds HTML before the video shortcode output.
     1829         *
     1830         * Give the possibility to insert some HTML code before the <video> tag
     1831         * generated by a video shortcode.
     1832         *
     1833         * @since 4.0.0
     1834         *
     1835         * @param string $html      The HTML snippet to insert before the <video> tag.
     1836         * @param string $library   Media library used for the video shortcode.
     1837         * @param int    $instances Unique numeric ID of this video shortcode instance.
     1838         */
     1839        $html = apply_filters('wp_video_shortcode_pre_html', '', $library, $instances);
    17941840        $html .= sprintf( '<video %s controls="controls">', join( ' ', $attr_strings ) );
    17951841
    17961842        $fileurl = '';
    function wp_video_shortcode( $attr, $content = '' ) { 
    18171863                $html .= trim( $content );
    18181864        }
    18191865
    1820         if ( 'mediaelement' === $library )
    1821                 $html .= wp_mediaelement_fallback( $fileurl );
     1866        /**
     1867         * Adds HTML inside the video shortcode output.
     1868         *
     1869         * Give the possibility to insert some HTML code inside the <video> tag
     1870         * generated by a video shortcode.
     1871         *
     1872         * @since 4.0.0
     1873         *
     1874         * @param string $html    The HTML snippet to append into the <video> tag.
     1875         * @param string $library Media library used for the video shortcode.
     1876         * @param string $fileurl The URL of the video file.
     1877         * @param int    $post_id Post ID.
     1878         */
     1879        $html .= apply_filters('wp_video_shortcode_inside_html', '', $library, $fileurl, $post_id);
    18221880        $html .= '</video>';
    18231881
    18241882        $html = sprintf( '<div style="width: %dpx; max-width: 100%%;" class="wp-video">%s</div>', $width, $html );
    function wp_video_shortcode( $attr, $content = '' ) { 
    18381896}
    18391897add_shortcode( 'video', 'wp_video_shortcode' );
    18401898
     1899function wp_mediaelement_video_shortcode_pre_html($html, $library, $instances) {
     1900    if ( 'mediaelement' === $library && 1 === $instances )
     1901                $html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
     1902    return $html;
     1903}
     1904add_filter('wp_video_shortcode_pre_html', 'wp_mediaelement_video_shortcode_pre_html', 10, 3);
     1905
     1906function wp_mediaelement_video_shortcode_inside_html($html, $library, $fileurl, $post_id) {
     1907        if ( 'mediaelement' === $library )
     1908                $html .= wp_mediaelement_fallback( $fileurl );
     1909        return $html;
     1910}
     1911add_filter('wp_video_shortcode_inside_html', 'wp_mediaelement_video_shortcode_inside_html', 10, 4);
     1912
    18411913/**
    18421914 * Display previous image link that has the same post parent.
    18431915 *