Skip to content
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 6 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'] ) ) {
Copy link
Contributor

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?

if ($mime_types['wav'] && !isset($mime_types['x-wav']) && !isset($mime_types['wav|x-wav'])) {
        $mime_types['x-wav'] = 'audio/wav';
    }

But no big deal, the code already looks good 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing!!

Or maybe we can simplify it like this?

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.

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 );
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
Loading