WordPress
对上传的文件类型是有限制的,在这里,我们以在子主题twentyfifteen-child
中增加扩展名为.bz2
的文件类型为例子。
首先编辑子主题的functions.php
文件
1 |
$ sudo vim /var/www/wordpress/wp-content/themes/twentyfifteen-child/functions.php |
在文件尾部增加如下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php /*BUG Fix for after wordpress https://core.trac.wordpress.org/ticket/21299*/ add_filter( 'wp_check_filetype_and_ext', 'upload_mimes_fix_after_47', 10, 4 ); function upload_mimes_fix_after_47($data, $file, $filename, $mimes) { global $wp_version; if( $wp_version == '4.7' || ( (float) $wp_version < 4.7 ) ) { return $data; } $filetype = wp_check_filetype( $filename, $mimes ); return [ 'ext' => $filetype['ext'], 'type' => $filetype['type'], 'proper_filename' => $data['proper_filename'] ]; } /*add upload file type*/ add_filter('upload_mimes', 'custom_upload_mimes'); function custom_upload_mimes ( $existing_mimes=array() ) { $existing_mimes['bz2'] = 'application/octet-stream'; return $existing_mimes; } ?> |