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.
Built from https://develop.svn.wordpress.org/trunk@55271


git-svn-id: http://core.svn.wordpress.org/trunk@54804 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2023-02-07 16:00:42 +00:00
parent f7b69e3d1f
commit 9f8f0aa58e
4 changed files with 19 additions and 3 deletions

View File

@ -19,6 +19,8 @@
* @return {void}
*/
function initialize() {
var selectors = [];
if ( typeof _wpmejsSettings !== 'undefined' ) {
settings = $.extend( true, {}, _wpmejsSettings );
}
@ -63,8 +65,18 @@
}
};
if ( 'undefined' === typeof settings.videoShortcodeLibrary || 'mediaelement' === settings.videoShortcodeLibrary ) {
selectors.push( '.wp-video-shortcode' );
}
if ( 'undefined' === typeof settings.audioShortcodeLibrary || 'mediaelement' === settings.audioShortcodeLibrary ) {
selectors.push( '.wp-audio-shortcode' );
}
if ( ! selectors.length ) {
return;
}
// Only initialize new media elements.
$( '.wp-audio-shortcode, .wp-video-shortcode' )
$( selectors.join( ', ' ) )
.not( '.mejs-container' )
.filter(function () {
return ! $( this ).parent().hasClass( 'mejs-mediaelement' );

View File

@ -1 +1 @@
!function(e,n){e.wp=e.wp||{},e.wp.mediaelement=new function(){var e={};return{initialize:function(){(e="undefined"!=typeof _wpmejsSettings?n.extend(!0,{},_wpmejsSettings):e).classPrefix="mejs-",e.success=e.success||function(e){var n,t;e.rendererName&&-1!==e.rendererName.indexOf("flash")&&(n=e.attributes.autoplay&&"false"!==e.attributes.autoplay,t=e.attributes.loop&&"false"!==e.attributes.loop,n&&e.addEventListener("canplay",function(){e.play()},!1),t)&&e.addEventListener("ended",function(){e.play()},!1)},e.customError=function(e,n){if(-1!==e.rendererName.indexOf("flash")||-1!==e.rendererName.indexOf("flv"))return'<a href="'+n.src+'">'+mejsL10n.strings["mejs.download-file"]+"</a>"},n(".wp-audio-shortcode, .wp-video-shortcode").not(".mejs-container").filter(function(){return!n(this).parent().hasClass("mejs-mediaelement")}).mediaelementplayer(e)}}},n(e.wp.mediaelement.initialize)}(window,jQuery);
!function(e,n){e.wp=e.wp||{},e.wp.mediaelement=new function(){var t={};return{initialize:function(){var e=[];(t="undefined"!=typeof _wpmejsSettings?n.extend(!0,{},_wpmejsSettings):t).classPrefix="mejs-",t.success=t.success||function(e){var t,n;e.rendererName&&-1!==e.rendererName.indexOf("flash")&&(t=e.attributes.autoplay&&"false"!==e.attributes.autoplay,n=e.attributes.loop&&"false"!==e.attributes.loop,t&&e.addEventListener("canplay",function(){e.play()},!1),n)&&e.addEventListener("ended",function(){e.play()},!1)},t.customError=function(e,t){if(-1!==e.rendererName.indexOf("flash")||-1!==e.rendererName.indexOf("flv"))return'<a href="'+t.src+'">'+mejsL10n.strings["mejs.download-file"]+"</a>"},void 0!==t.videoShortcodeLibrary&&"mediaelement"!==t.videoShortcodeLibrary||e.push(".wp-video-shortcode"),void 0!==t.audioShortcodeLibrary&&"mediaelement"!==t.audioShortcodeLibrary||e.push(".wp-audio-shortcode"),e.length&&n(e.join(", ")).not(".mejs-container").filter(function(){return!n(this).parent().hasClass("mejs-mediaelement")}).mediaelementplayer(t)}}},n(e.wp.mediaelement.initialize)}(window,jQuery);

View File

@ -1111,6 +1111,10 @@ function wp_default_scripts( $scripts ) {
'pluginPath' => includes_url( 'js/mediaelement/', 'relative' ),
'classPrefix' => 'mejs-',
'stretching' => 'responsive',
/** This filter is documented in wp-includes/media.php */
'audioShortcodeLibrary' => apply_filters( 'wp_audio_shortcode_library', 'mediaelement' ),
/** This filter is documented in wp-includes/media.php */
'videoShortcodeLibrary' => apply_filters( 'wp_video_shortcode_library', 'mediaelement' ),
);
did_action( 'init' ) && $scripts->localize(
'mediaelement',

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.2-alpha-55270';
$wp_version = '6.2-alpha-55271';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.