这是一个不完美的解决方案,它迫使Wordpress检测TTF文件的方式使用文件扩展名,然后挂钩upload_mimes
对于我们指定的MIME类型。部分答案摘自https://diviengine.com/how-to-fix-sorry-this-file-type-is-not-permitted-for-security-reasons/
首先介绍Wordpress检测/报告TTF文件类型的方式:
function divi_engine_font_correct_filetypes( $data, $file, $filename, $mimes, $real_mime ) {
if ( ! empty( $data[\'ext\'] ) && ! empty( $data[\'type\'] ) ) {
return $data;
}
$wp_file_type = wp_check_filetype( $filename, $mimes );
// Check for the file type you want to enable, e.g. \'svg\'.
if ( \'ttf\' === $wp_file_type[\'ext\'] ) {
$data[\'ext\'] = \'ttf\';
$data[\'type\'] = \'font/ttf\';
}
if ( \'otf\' === $wp_file_type[\'ext\'] ) {
$data[\'ext\'] = \'otf\';
$data[\'type\'] = \'font/otf\';
}
return $data;
}
add_filter( \'wp_check_filetype_and_ext\', \'divi_engine_font_correct_filetypes\', 10, 5 );
然后挂钩
upload_mimes
对于此扩展/mime类型:
function allow_custom_mime_types( $mimes ) {
// New allowed mime types.
$mimes[\'ttf\'] = \'font/ttf\';
return $mimes;
}
add_filter( \'upload_mimes\', \'allow_custom_mime_types\' );