Skip to content

Commit

Permalink
Media: add x-wav mime type for wav files in Firefox (WordPress#66850)
Browse files Browse the repository at this point in the history
Adding x-wav support because Firefox uses that identifier
Check if wav does not exist in case some plugins or themes have already filtered it out.

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: Imran92 <[email protected]>
  • Loading branch information
3 people authored Nov 12, 2024
1 parent 2a3e379 commit 074dc52
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backport-changelog/6.8/7265.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/7265

* https://github.com/WordPress/gutenberg/pull/66850
35 changes: 35 additions & 0 deletions lib/compat/wordpress-6.8/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* Adds the x-wav mime type to the list of mime types.
* This is necessary for Firefox as it uses the identifier for uploaded .wav files.
* Core backport should add the following to the default mime_types filters in
* `wp_get_mime_types()` in wp-includes/functions.php:
*
* `'wav|x-wav' => 'audio/wav'`
*
* @since 6.8.0
*
* @param string[] $mime_types Mime types.
* @return string[] Mime types keyed by the file extension regex corresponding to those types.
*/
function gutenberg_get_mime_types_6_8( $mime_types ) {
/*
* Only add support if there is existing support for 'wav'.
* Some plugins may have deliberately disabled it.
*/
if ( ! $mime_types['wav'] && ! isset( $mime_types['wav|x-wav'] ) ) {
return $mime_types;
}
/*
* Also, given that other themes or plugins may have already
* tried to add x-wav type support, only
* add the mime type if it doesn't already exist
* to avoid overriding any customizations.
*/
if ( ! isset( $mime_types['x-wav'] ) && ! isset( $mime_types['wav|x-wav'] ) ) {
$mime_types['x-wav'] = 'audio/wav';
}
return $mime_types;
}
add_filter( 'mime_types', 'gutenberg_get_mime_types_6_8', 99 );
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function gutenberg_is_experiment_enabled( $name ) {
// WordPress 6.8 compat.
require __DIR__ . '/compat/wordpress-6.8/preload.php';
require __DIR__ . '/compat/wordpress-6.8/blocks.php';
require __DIR__ . '/compat/wordpress-6.8/functions.php';

// Experimental features.
require __DIR__ . '/experimental/block-editor-settings-mobile.php';
Expand Down

0 comments on commit 074dc52

Please sign in to comment.