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/wp-includes/media.php
+++ b/wp-includes/media.php
@@ -1571,9 +1571,7 @@ function wp_audio_shortcode( $attr, $content = '' ) {
 		$attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
 	}
 
-	$html = '';
-	if ( 'mediaelement' === $library && 1 === $instances )
-		$html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
+	$html = apply_filters('wp_audio_shortcode_pre_html', '', $library, $instances);
 	$html .= sprintf( '<audio %s controls="controls">', join( ' ', $attr_strings ) );
 
 	$fileurl = '';
@@ -1588,8 +1586,7 @@ function wp_audio_shortcode( $attr, $content = '' ) {
 		}
 	}
 
-	if ( 'mediaelement' === $library )
-		$html .= wp_mediaelement_fallback( $fileurl );
+	$html .= apply_filters('wp_audio_shortcode_inside_html', '', $library, $fileurl, $post_id);
 	$html .= '</audio>';
 
 	/**
@@ -1607,6 +1604,20 @@ function wp_audio_shortcode( $attr, $content = '' ) {
 }
 add_shortcode( 'audio', 'wp_audio_shortcode' );
 
+function wp_mediaelement_audio_shortcode_pre_html($html, $library, $instances) {
+    if ( 'mediaelement' === $library && 1 === $instances )
+		$html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
+    return $html;
+}
+add_filter('wp_audio_shortcode_pre_html', 'wp_mediaelement_audio_shortcode_pre_html', 10, 3);
+
+function wp_mediaelement_audio_shortcode_inside_html($html, $library, $fileurl, $post_id) {
+	if ( 'mediaelement' === $library )
+		$html .= wp_mediaelement_fallback( $fileurl );
+	return $html;
+}
+add_filter('wp_audio_shortcode_inside_html', 'wp_mediaelement_audio_shortcode_inside_html', 10, 4);
+
 /**
  * Return a filtered list of WP-supported video formats
  *
@@ -1788,9 +1799,7 @@ function wp_video_shortcode( $attr, $content = '' ) {
 		$attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
 	}
 
-	$html = '';
-	if ( 'mediaelement' === $library && 1 === $instances )
-		$html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
+	$html = apply_filters('wp_video_shortcode_pre_html', '', $library, $instances);
 	$html .= sprintf( '<video %s controls="controls">', join( ' ', $attr_strings ) );
 
 	$fileurl = '';
@@ -1817,8 +1826,7 @@ function wp_video_shortcode( $attr, $content = '' ) {
 		$html .= trim( $content );
 	}
 
-	if ( 'mediaelement' === $library )
-		$html .= wp_mediaelement_fallback( $fileurl );
+	$html .= apply_filters('wp_video_shortcode_inside_html', '', $library, $fileurl, $post_id);
 	$html .= '</video>';
 
 	$html = sprintf( '<div style="width: %dpx; max-width: 100%%;" class="wp-video">%s</div>', $width, $html );
@@ -1838,6 +1846,20 @@ function wp_video_shortcode( $attr, $content = '' ) {
 }
 add_shortcode( 'video', 'wp_video_shortcode' );
 
+function wp_mediaelement_video_shortcode_pre_html($html, $library, $instances) {
+    if ( 'mediaelement' === $library && 1 === $instances )
+		$html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
+    return $html;
+}
+add_filter('wp_video_shortcode_pre_html', 'wp_mediaelement_video_shortcode_pre_html', 10, 3);
+
+function wp_mediaelement_video_shortcode_inside_html($html, $library, $fileurl, $post_id) {
+	if ( 'mediaelement' === $library )
+		$html .= wp_mediaelement_fallback( $fileurl );
+	return $html;
+}
+add_filter('wp_video_shortcode_inside_html', 'wp_mediaelement_video_shortcode_inside_html', 10, 4);
+
 /**
  * Display previous image link that has the same post parent.
  *
-- 
1.9.1

