-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathallow-models-upload.php
39 lines (33 loc) · 1.05 KB
/
allow-models-upload.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
<?php
/**
* Plugin Name: Allow Models Upload
*
* Description: Allow users to upload <em>.gltf</em> and <em>.glb</em> files into WordPress Media Library.
* Author: JimJ92120
* Author URI: https://github.com/JimJ92120
*
* Version: 0.1.0
* Requires at least: 5.9
* Requires PHP: 7.4
*/
add_filter('upload_mimes', function($mime_types) {
$mime_types['gltf'] = 'model/gltf+json';
$mime_types['glb'] = 'model/gltf-binary';
return $mime_types;
});
add_filter('wp_check_filetype_and_ext', function($data, $file, $filename, $mime_types, $real_mime_type) {
if (empty($data['ext'])
|| empty($data['type'])
) {
$file_type = wp_check_filetype($filename, $mime_types);
if ('gltf' === $file_type['ext']) {
$data['ext'] = 'gltf';
$data['type'] = 'model/gltf+json';
}
if ('glb' === $file_type['ext']) {
$data['ext'] = 'glb';
$data['type'] = 'model/glb-binary';
}
}
return $data;
}, 10, 5);