can not upload file .vtt on wordpress 5.0.1

I did some debugging and was able to reproduce and solve the issue, but unfortunately I was not able to figure out the specific cause. Generally speaking, it seems that .vtt files are failing the check performed by wp_check_filetype_and_ext().

I was able to upload .vtt files (Only tested on WP 5.0.1) after creating a simple plugin containing the following code adapted from this answer by brasofilo:

// Sets the extension and mime type for .vtt files.
add_filter( 'wp_check_filetype_and_ext', 'wpse_file_and_ext', 10, 4 );
function wpse_file_and_ext( $types, $file, $filename, $mimes ) {
    if ( false !== strpos( $filename, '.vtt' ) ) {
        $types['ext'] = 'vtt';
        $types['type'] = 'text/vtt';
    }

    return $types;
}

I also noted that .vtt files are already included in the allowed mimes by default by WP, so it should not be (and indeed isn’t) necessary to add the vtt mime type to the list handled by the upload_mimes filter. e.g.:

add_filter( 'upload_mimes', 'wpse_mime_types');
function wpse_mime_types( $mimes ) {
  $mimes['vtt'] = 'text/vtt';
  return $mimes;
}

because the entry for vtt already exists.

I’m using a simple demonstration VTT file named test.vtt with the following contents:

WEBVTT – This file has no cues.

Leave a Comment