[wp-trac] [WordPress Trac] #61398: Missing src attribute on <audio> tag prevents m4a audio files playing in safari.

WordPress Trac noreply at wordpress.org
Fri Jun 7 10:26:10 UTC 2024


#61398: Missing src attribute on <audio> tag prevents m4a audio files playing in
safari.
--------------------------+-----------------------------
 Reporter:  ericmulder    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 We have discovered an issue where the audio shortcode doesn't work in
 safari. When you add a m4a file to the shortcode, and you don't use the
 wp-mediaelement library the <audio> tag is created without a src element.
 [https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/AudioandVideoTagBasics/AudioandVideoTagBasics.html
 Safari expect a src element], and if we add one the m4a audio tag works.

 We have patched this with a filter, but I think it would be better to fix
 this in the core.

 I see that on wp-includes/media.php:3067 $html_atts are set, but no 'src'
 attribute is present. Shall I create a pull request for this?

 Our patch:
 {{{
 function peek_audio_shortcode($html, $atts, $audio, $post_id, $library) {
     // check if the <audio> tag has a src attribute (use a preg match
 <audio src="" >). If not, get the first <source> tag
     if (!preg_match('/<audio[^>]*src\s*=\s*"[^"]*"[^>]*>/', $html)) {
         // get the first source tag
         preg_match('/<source[^>]*src\s*=\s*"([^"]*)"[^>]*>/', $html,
 $matches);
         $src = $matches[1];
         // now add the src="" to the audio tag
         $html = preg_replace('/<audio/', '<audio src="' . $src . '"',
 $html);
     }
     return $html;
 }
 add_filter('wp_audio_shortcode', 'peek_audio_shortcode', 10, 5);
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61398>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list