From 53a6770030c006512b6f2812158905af3c7309f0 Mon Sep 17 00:00:00 2001 From: Dhrupo Date: Tue, 10 Nov 2026 21:09:23 +0600 Subject: [PATCH 1/2] Media: Stop adding a cache-busting query arg to media source URLs. wp_audio_shortcode(), wp_video_shortcode(), and the media modal's prepareSrc() appended an auto-incrementing `&_=N` argument to every media source URL, working around MediaElement.js conflicts when several players in the DOM share one src. Mutating every URL breaks signed URLs from CDNs, and the conflict this worked around no longer applies now that the Flash fallback has been removed. Drop the argument entirely, and with it the prepareSrc() helper. Fixes #66639. --- src/js/media/views/attachment/details.js | 3 +-- src/js/media/views/audio-details.js | 2 +- src/js/media/views/media-details.js | 21 --------------------- src/js/media/views/video-details.js | 2 +- src/wp-includes/media.php | 6 ++---- tests/phpunit/tests/media.php | 2 +- 6 files changed, 6 insertions(+), 30 deletions(-) diff --git a/src/js/media/views/attachment/details.js b/src/js/media/views/attachment/details.js index 8317dbdfdada5..80f871b87ed76 100644 --- a/src/js/media/views/attachment/details.js +++ b/src/js/media/views/attachment/details.js @@ -266,8 +266,7 @@ Details = Attachment.extend(/** @lends wp.media.view.Attachment.Details.prototyp wp.media.mixin.removeAllPlayers(); this.$( 'audio, video' ).each( function (i, elem) { - var el = wp.media.view.MediaDetails.prepareSrc( elem ); - new window.MediaElementPlayer( el, wp.media.mixin.mejsSettings ); + new window.MediaElementPlayer( elem, wp.media.mixin.mejsSettings ); } ); } }); diff --git a/src/js/media/views/audio-details.js b/src/js/media/views/audio-details.js index afafca3080673..b51580cbbd338 100644 --- a/src/js/media/views/audio-details.js +++ b/src/js/media/views/audio-details.js @@ -25,7 +25,7 @@ AudioDetails = MediaDetails.extend(/** @lends wp.media.view.AudioDetails.prototy if ( audio.is(':hidden') ) { audio.show(); } - this.media = MediaDetails.prepareSrc( audio.get(0) ); + this.media = audio.get(0); } else { audio.hide(); this.media = false; diff --git a/src/js/media/views/media-details.js b/src/js/media/views/media-details.js index 5fdeb64a05cd1..33cd53aaddb59 100644 --- a/src/js/media/views/media-details.js +++ b/src/js/media/views/media-details.js @@ -179,27 +179,6 @@ MediaDetails = AttachmentDisplay.extend(/** @lends wp.media.view.MediaDetails.pr scrollToTop: function() { this.$( '.embed-media-settings' ).scrollTop( 0 ); } -},/** @lends wp.media.view.MediaDetails */{ - instances : 0, - /** - * When multiple players in the DOM contain the same src, things get weird. - * - * @param {HTMLElement} elem The HTML element containing the media sources to be prepared. - * @return {HTMLElement} The prepared element. - */ - prepareSrc : function( elem ) { - var i = MediaDetails.instances++; - _.each( $( elem ).find( 'source' ), function( source ) { - source.src = [ - source.src, - source.src.indexOf('?') > -1 ? '&' : '?', - '_=', - i - ].join(''); - } ); - - return elem; - } }); module.exports = MediaDetails; diff --git a/src/js/media/views/video-details.js b/src/js/media/views/video-details.js index ac5c91e3c634f..532173d2ade84 100644 --- a/src/js/media/views/video-details.js +++ b/src/js/media/views/video-details.js @@ -27,7 +27,7 @@ VideoDetails = MediaDetails.extend(/** @lends wp.media.view.VideoDetails.prototy } if ( ! video.hasClass( 'youtube-video' ) && ! video.hasClass( 'vimeo-video' ) ) { - this.media = MediaDetails.prepareSrc( video.get(0) ); + this.media = video.get(0); } else { this.media = video.get(0); } diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 4cd69ade6cbb7..fa6f1d20e7393 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -3683,8 +3683,7 @@ function wp_audio_shortcode( $attr, $content = '' ) { } $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() ); - $url = add_query_arg( '_', $instance, $atts[ $fallback ] ); - $html .= sprintf( $source, $type['type'], esc_url( $url ) ); + $html .= sprintf( $source, $type['type'], esc_url( $atts[ $fallback ] ) ); } } @@ -3966,8 +3965,7 @@ function wp_video_shortcode( $attr, $content = '' ) { } else { $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() ); } - $url = add_query_arg( '_', $instance, $atts[ $fallback ] ); - $html .= sprintf( $source, $type['type'], esc_url( $url ) ); + $html .= sprintf( $source, $type['type'], esc_url( $atts[ $fallback ] ) ); } } diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index af84065113267..261ec42846e58 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -1550,7 +1550,7 @@ static function ( $html, $attr, $content, $id ) use ( &$instance ) { $expected = '
' . '