Created
April 16, 2020 22:11
-
-
Save gagimilicevic/172e05e3b7372d8b9301c02e2aef4bfd to your computer and use it in GitHub Desktop.
Enable SVG support and enable svg upload
This file contains hidden or 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
/** | |
* Enable SVG upload. | |
*/ | |
function dwply_svgs_upload_mimes( $mimes = array() ) { | |
// allow SVG file upload | |
$mimes['svg'] = 'image/svg+xml'; | |
$mimes['svgz'] = 'image/svg+xml'; | |
return $mimes; | |
} | |
add_filter( 'upload_mimes', 'dwply_svgs_upload_mimes', 99 ); | |
/** | |
* Check Mime Types | |
*/ | |
function dwply_svgs_upload_check( $checked, $file, $filename, $mimes ) { | |
if ( ! $checked['type'] ) { | |
$check_filetype = wp_check_filetype( $filename, $mimes ); | |
$ext = $check_filetype['ext']; | |
$type = $check_filetype['type']; | |
$proper_filename = $filename; | |
if ( $type && 0 === strpos( $type, 'image/' ) && $ext !== 'svg' ) { | |
$ext = $type = false; | |
} | |
$checked = compact( 'ext','type','proper_filename' ); | |
} | |
return $checked; | |
} | |
add_filter( 'wp_check_filetype_and_ext', 'dwply_svgs_upload_check', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment