-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Media: add x-wav
mime type for wav files in Firefox
#66850
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
59c0def
Adding x-wav support because Firefox uses that identifier
ramonjd 95f566c
Add compat file
ramonjd dc55731
backport log
ramonjd d11c88b
Updated the check
ramonjd 46afee1
Tab for you!
ramonjd 50503d6
Check if wav does not exist in case some plugins or themes have alrea…
ramonjd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] ) ) { | ||
ramonjd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$mime_types['x-wav'] = 'audio/wav'; | ||
} | ||
return $mime_types; | ||
} | ||
add_filter( 'mime_types', 'gutenberg_get_mime_types_6_8', 99 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolute Nitpick: We already have the
! isset( $mime_types['wav|x-wav'] )
check in line 30, do we also need it here?Or maybe we can simplify it like this?
But no big deal, the code already looks good 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reviewing!!
You're right, and that's how I had it originally, however I split it up to make it easier to read, and for my small brain to process.
So, condition 1 says "If wav AND wav|x-wav are not there we assume it's a deliberate measure by the theme/plugin and return early"
Condition 2 just checks if x-wav is absent.