Forked from kamalahmed/fix-svg-upload-error-in-wordpress.php
Last active
November 11, 2021 09:25
A simple plugin that makes it possible to upload USDZ files in WordPress Media Manager
This file contains 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 USDZ mime in Wordpress Media Library | |
* Plugin URI: https://gist.github.com/alexmoise/201a3b1196facb8343e82d0590f9b1ab | |
* Description: A simple plugin that makes it possible to upload USDZ files in Media Manager. Don't forget to add the MIME type 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.2.81 | |
* Author: Alex Moise | |
* Author URI: https://moise.pro | |
*/ | |
function mos_filter_fix_wp_check_filetype_and_ext( $data, $file, $filename, $mimes ) { | |
if ( ! empty( $data['ext'] ) && ! empty( $data['type'] ) ) { | |
return $data; | |
} | |
$registered_file_types = ['usdz' => 'model/vnd.usdz+zip|application/octet-stream|model/x-vnd.usdz+zip']; | |
$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 mos_allow_usdz( $mime_types ) { | |
if ( ! in_array( 'usdz', $mime_types ) ) { | |
$mime_types['usdz'] = 'model/vnd.usdz+zip|application/octet-stream|model/x-vnd.usdz+zip'; | |
} | |
return $mime_types; | |
} | |
add_filter( 'wp_check_filetype_and_ext', 'mos_filter_fix_wp_check_filetype_and_ext', 10, 4 ); | |
add_filter( 'upload_mimes', 'mos_allow_usdz' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment