Created
December 19, 2018 13:51
-
-
Save YuzuruSano/9528069f0f0ee467c0427ed52fc7d6c8 to your computer and use it in GitHub Desktop.
WordPress 4.9.9でメディアライブラリからcsvをアップできない対策(場当たり的)
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 | |
| add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' ); | |
| function custom_upload_filter( $file ){ | |
| if('csv' == substr($file['name'], strrpos($file['name'], '.') + 1)){ | |
| $file['type'] = 'text/csv'; | |
| } | |
| if($file['type'] == 'text/csv' && mime_content_type($file['tmp_name']) == 'text/plain'){ | |
| add_filter('upload_mimes', function($existing_mimes){ | |
| $existing_mimes['csv'] = 'text/plain'; | |
| return $existing_mimes; | |
| }); | |
| } | |
| return $file; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment