Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
SVG fix for WP 4.7.1+
add_filter('wp_check_filetype_and_ext', 'ignore_upload_ext', 10, 4);
function ignore_upload_ext($checked, $file, $filename, $mimes){
//we only need to worry if WP failed the first pass
//rebuild the type info
$wp_filetype = wp_check_filetype( $filename, $mimes );
$ext = $wp_filetype['ext'];
$type = $wp_filetype['type'];
$proper_filename = $filename;
//preserve failure for non-svg images
if($type && 0 === strpos($type, 'image/') && $ext !== 'svg'){
$ext = $type = false;
//everything else gets an OK, so e.g. we've disabled the error-prone finfo-related checks WP just went through. whether or not the upload will be allowed depends on the <code>upload_mimes</code>, etc.
$checked = compact('ext','type','proper_filename');
return $checked;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment