Created
January 15, 2017 11:41
-
-
Save leurdo/09dcb8488019cd57e4aa91eafd234c24 to your computer and use it in GitHub Desktop.
SVG fix for WP 4.7.1+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
if(!$checked['type']){ | |
//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