Skip to content

Commit d499513

Browse files
committed
Media: Enable selective optout for video and audio shortcodes.
Make the JavaScript selectors for audio and video shortcodes aware of the state of the `wp_video_shortcode_library` and `wp_audio_shortcode_library` filters. Allow extenders to replace the library for either media shortcode. Props westonruter, joedolson, rudlinkon, obayedmamur. Fixes #40144. git-svn-id: https://develop.svn.wordpress.org/trunk@55271 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6fe0e51 commit d499513

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/js/_enqueues/vendor/mediaelement/wp-mediaelement.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* @return {void}
2020
*/
2121
function initialize() {
22+
var selectors = [];
23+
2224
if ( typeof _wpmejsSettings !== 'undefined' ) {
2325
settings = $.extend( true, {}, _wpmejsSettings );
2426
}
@@ -63,8 +65,18 @@
6365
}
6466
};
6567

68+
if ( 'undefined' === typeof settings.videoShortcodeLibrary || 'mediaelement' === settings.videoShortcodeLibrary ) {
69+
selectors.push( '.wp-video-shortcode' );
70+
}
71+
if ( 'undefined' === typeof settings.audioShortcodeLibrary || 'mediaelement' === settings.audioShortcodeLibrary ) {
72+
selectors.push( '.wp-audio-shortcode' );
73+
}
74+
if ( ! selectors.length ) {
75+
return;
76+
}
77+
6678
// Only initialize new media elements.
67-
$( '.wp-audio-shortcode, .wp-video-shortcode' )
79+
$( selectors.join( ', ' ) )
6880
.not( '.mejs-container' )
6981
.filter(function () {
7082
return ! $( this ).parent().hasClass( 'mejs-mediaelement' );

src/wp-includes/script-loader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,10 @@ function wp_default_scripts( $scripts ) {
11111111
'pluginPath' => includes_url( 'js/mediaelement/', 'relative' ),
11121112
'classPrefix' => 'mejs-',
11131113
'stretching' => 'responsive',
1114+
/** This filter is documented in wp-includes/media.php */
1115+
'audioShortcodeLibrary' => apply_filters( 'wp_audio_shortcode_library', 'mediaelement' ),
1116+
/** This filter is documented in wp-includes/media.php */
1117+
'videoShortcodeLibrary' => apply_filters( 'wp_video_shortcode_library', 'mediaelement' ),
11141118
);
11151119
did_action( 'init' ) && $scripts->localize(
11161120
'mediaelement',

0 commit comments

Comments
 (0)