Skip to content

Instantly share code, notes, and snippets.

@alpipego
Created June 24, 2021 07:13
Show Gist options
  • Save alpipego/50cd2e158ab52ce260aa758c4a626f0a to your computer and use it in GitHub Desktop.
Save alpipego/50cd2e158ab52ce260aa758c4a626f0a to your computer and use it in GitHub Desktop.
Upload USDZ/Reality files for AR Quick Look to WordPress
<?php
/**
* Plugin Name: Upload AR Quick Look files
* Description: Upload AR Quick Look files (usdz or reality) to your WordPress media library.
* Author: Alexander Goller
* Author URI: https://alexandergoller.com
*/
$arMimes = [
'usdz' => 'model/vnd.usdz+zip|application/octet-stream|model/x-vnd.usdz+zip',
'reality' => 'model/vnd.reality|application/octet-stream|model/x-vnd.reality',
];
add_filter('wp_check_filetype_and_ext', function (array $data, string $file, string $filename, $mimes) use ($arMimes): array {
if ( ! empty($data['ext']) && ! empty($data['type'])) {
return $data;
}
$filetype = wp_check_filetype($filename, $mimes);
if ( ! array_key_exists($filetype['ext'], $arMimes)) {
return $data;
}
return [
'ext' => $filetype['ext'],
'type' => $filetype['type'],
'proper_filename' => $data['proper_filename'],
];
}, 10, 4);
add_filter('upload_mimes', function (array $mimeTypes) use ($arMimes): array {
if (array_key_exists('usdz', $mimeTypes)) {
return $mimeTypes;
}
foreach ($arMimes as $ext => $mime) {
$mimeTypes[$ext] = $mime;
}
return $mimeTypes;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment