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 = '' ) { |
1571 | 1571 | $attr_strings[] = $k . '="' . esc_attr( $v ) . '"'; |
1572 | 1572 | } |
1573 | 1573 | |
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); |
1577 | 1587 | $html .= sprintf( '<audio %s controls="controls">', join( ' ', $attr_strings ) ); |
1578 | 1588 | |
1579 | 1589 | $fileurl = ''; |
… |
… |
function wp_audio_shortcode( $attr, $content = '' ) { |
1588 | 1598 | } |
1589 | 1599 | } |
1590 | 1600 | |
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); |
1593 | 1615 | $html .= '</audio>'; |
1594 | 1616 | |
1595 | 1617 | /** |
… |
… |
function wp_audio_shortcode( $attr, $content = '' ) { |
1607 | 1629 | } |
1608 | 1630 | add_shortcode( 'audio', 'wp_audio_shortcode' ); |
1609 | 1631 | |
| 1632 | function 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 | } |
| 1637 | add_filter('wp_audio_shortcode_pre_html', 'wp_mediaelement_audio_shortcode_pre_html', 10, 3); |
| 1638 | |
| 1639 | function 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 | } |
| 1644 | add_filter('wp_audio_shortcode_inside_html', 'wp_mediaelement_audio_shortcode_inside_html', 10, 4); |
| 1645 | |
1610 | 1646 | /** |
1611 | 1647 | * Return a filtered list of WP-supported video formats |
1612 | 1648 | * |
… |
… |
function wp_video_shortcode( $attr, $content = '' ) { |
1788 | 1824 | $attr_strings[] = $k . '="' . esc_attr( $v ) . '"'; |
1789 | 1825 | } |
1790 | 1826 | |
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); |
1794 | 1840 | $html .= sprintf( '<video %s controls="controls">', join( ' ', $attr_strings ) ); |
1795 | 1841 | |
1796 | 1842 | $fileurl = ''; |
… |
… |
function wp_video_shortcode( $attr, $content = '' ) { |
1817 | 1863 | $html .= trim( $content ); |
1818 | 1864 | } |
1819 | 1865 | |
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); |
1822 | 1880 | $html .= '</video>'; |
1823 | 1881 | |
1824 | 1882 | $html = sprintf( '<div style="width: %dpx; max-width: 100%%;" class="wp-video">%s</div>', $width, $html ); |
… |
… |
function wp_video_shortcode( $attr, $content = '' ) { |
1838 | 1896 | } |
1839 | 1897 | add_shortcode( 'video', 'wp_video_shortcode' ); |
1840 | 1898 | |
| 1899 | function 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 | } |
| 1904 | add_filter('wp_video_shortcode_pre_html', 'wp_mediaelement_video_shortcode_pre_html', 10, 3); |
| 1905 | |
| 1906 | function 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 | } |
| 1911 | add_filter('wp_video_shortcode_inside_html', 'wp_mediaelement_video_shortcode_inside_html', 10, 4); |
| 1912 | |
1841 | 1913 | /** |
1842 | 1914 | * Display previous image link that has the same post parent. |
1843 | 1915 | * |