font enabler

Written by

in

// Allow font uploads (TTF, OTF, WOFF, WOFF2, EOT)
add_filter(\’upload_mimes\’, function($mimes) {
$mimes[\’ttf\’] = \’font/ttf\’;
$mimes[\’otf\’] = \’font/otf\’;
$mimes[\’woff\’] = \’font/woff\’;
$mimes[\’woff2\’] = \’font/woff2\’;
$mimes[\’eot\’] = \’application/vnd.ms-fontobject\’; // important
return $mimes;
});

// Fix file type validation issue (WordPress security check)
add_filter(\’wp_check_filetype_and_ext\’, function($data, $file, $filename, $mimes) {
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));

if (in_array($ext, [\’ttf\’,\’otf\’,\’woff\’,\’woff2\’,\’eot\’])) {
$data[\’ext\’] = $ext;

if ($ext === \’eot\’) {
$data[\’type\’] = \’application/vnd.ms-fontobject\’;
} else {
$data[\’type\’] = \’font/\’ . $ext;
}
}

return $data;
}, 10, 4);