-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultipleMimes.php
42 lines (38 loc) · 1.67 KB
/
MultipleMimes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
class phonicscore_opensheetmusicdisplay_MultipleMimes {
public static function init() {
add_filter( 'wp_check_filetype_and_ext', [self::class, 'add_multiple_mime_types'], 99, 3 );
}
public static function add_multiple_mime_types( $check, $file, $filename ) {
if ( empty( $check['ext'] ) && empty( $check['type'] ) ) {
foreach ( self::get_allowed_mime_types() as $mime ) {
remove_filter( 'wp_check_filetype_and_ext', [ self::class, 'add_multiple_mime_types' ], 99 );
$mime_filter = function($mimes) use ($mime) {
return array_merge($mimes, $mime);
};
add_filter('upload_mimes', $mime_filter, 99);
$check = wp_check_filetype_and_ext( $file, $filename, $mime );
remove_filter('upload_mimes', $mime_filter, 99);
add_filter( 'wp_check_filetype_and_ext', [ self::class, 'add_multiple_mime_types' ], 99, 3 );
if ( ! empty( $check['ext'] ) || ! empty( $check['type'] ) ) {
return $check;
}
}
}
return $check;
}
public static function get_allowed_mime_types(){
return [
['musicxml' => 'application/vnd.recordare.musicxml+xml'],
['musicxml' => 'application/octet-stream'],
['musicxml' => 'text/xml'],
['musicxml' => 'application/xml'],
['xml' => 'text/xml'],
['xml' => 'application/xml'],
['xml' => 'application/octet-stream'],
['mxl' => 'application/vnd.recordare.musicxml'],
['mxl' => 'application/octet-stream']
];
}
}
?>