Forked from alexmoise/allow-usdz-in-wordpress-media-library.php
Last active
November 11, 2021 10:06
-
-
Save PixelPartner/d3362a9fad57165ba9d5bd76a3f5b4ee to your computer and use it in GitHub Desktop.
A plugin that makes it possible to upload Apple AR Quick Look files (.usdz + .reality) and glTF-binary (.glb) in WordPress Media Manager
This file contains hidden or 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
<?php | |
/** | |
* Plugin Name: Allow GLB, USDZ and Reality mime in Wordpress Media Library | |
* Plugin URI: https://gist.github.com/PixelPartner/d3362a9fad57165ba9d5bd76a3f5b4ee | |
* Description: A plugin that makes it possible to upload AR files in Media Manager. Don't forget to add the three MIME types in web server config if necessary! No settings necessary, just activate and upload USDZ files in media library as usually. Tested with WP 5.2.3 | |
* Version: 1.0.0 | |
* Author: Thomas Kumlehn | |
* Author URI: https://config-xr.mobi | |
*/ | |
function pix_filter_ar3d_wp_check_filetype_and_ext( $data, $file, $filename, $mimes ) { | |
if ( ! empty( $data['ext'] ) && ! empty( $data['type'] ) ) { | |
return $data; | |
} | |
$registered_file_types = [ | |
'glb' => 'model/gltf-binary', | |
'usdz' => 'model/vnd.usdz+zip|application/octet-stream|model/x-vnd.usdz+zip', | |
'reality' => 'model/vnd.reality' | |
]; | |
$filetype = wp_check_filetype( $filename, $mimes ); | |
if ( ! isset( $registered_file_types[ $filetype['ext'] ] ) ) { | |
return $data; | |
} | |
return [ | |
'ext' => $filetype['ext'], | |
'type' => $filetype['type'], | |
'proper_filename' => $data['proper_filename'], | |
]; | |
} | |
function pix_allow_ar3d( $mime_types ) { | |
if ( ! in_array( 'glb', $mime_types ) ) { | |
$mime_types['glb'] = 'model/gltf-binary'; | |
} | |
if ( ! in_array( 'usdz', $mime_types ) ) { | |
$mime_types['usdz'] = 'model/vnd.usdz+zip|application/octet-stream|model/x-vnd.usdz+zip'; | |
} | |
if ( ! in_array( 'reality', $mime_types ) ) { | |
$mime_types['reality'] = 'model/vnd.reality'; | |
} | |
return $mime_types; | |
} | |
add_filter( 'wp_check_filetype_and_ext', 'pix_filter_ar3d_wp_check_filetype_and_ext', 10, 4 ); | |
add_filter( 'upload_mimes', 'pix_allow_ar3d' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment