Let administrators upload file types WordPress blocks by default, such as subtitle files (.vtt), JSON or 3D models (.glb).
add_filter( 'upload_mimes', function ( array $mimes ): array {
if ( ! current_user_can( 'manage_options' ) ) {
return $mimes;
}
$mimes['vtt'] = 'text/vtt';
$mimes['json'] = 'application/json';
$mimes['glb'] = 'model/gltf-binary';
return $mimes;
} );
// WordPress double-checks the real file type. Tell it these are fine.
add_filter( 'wp_check_filetype_and_ext', function ( array $data, string $file, string $filename, $mimes ): array {
if ( ! empty( $data['ext'] ) || ! current_user_can( 'manage_options' ) ) {
return $data;
}
$allowed = [ 'vtt' => 'text/vtt', 'json' => 'application/json', 'glb' => 'model/gltf-binary' ];
$ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
if ( isset( $allowed[ $ext ] ) ) {
$data['ext'] = $ext;
$data['type'] = $allowed[ $ext ];
}
return $data;
}, 10, 4 );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
WordPress only accepts a fixed list of file types. Uploading a subtitle file for a video, or a JSON or 3D model file, gives “Sorry, you are not allowed to upload this file type”. This snippet allows a few more, for administrators only.
upload_mimes is the list of allowed extensions and their MIME types. The snippet adds three for administrators.
WordPress also checks the actual contents of each file. For plain text formats like VTT and JSON, that check often can’t confirm the type, so wp_check_filetype_and_ext fills in the type for these extensions when WordPress couldn’t.
.php, .phtml or .exe, or HTML files.Log in as an administrator and upload a .vtt file. It should be added to the Media Library.