Created
March 28, 2022 16:31
-
-
Save taciara/23588cff1ef485a499aa449da12afa54 to your computer and use it in GitHub Desktop.
Habilitar SVG no wordpress. Cole isso no seu functions.
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
<?php | |
// ############### ACEITAR SVG NO WORDPRESS ############### | |
function bodhi_svgs_upload_mimes( $mimes = array() ) { | |
if ( current_user_can( 'administrator' ) ) { | |
// allow SVG file upload | |
$mimes['svg'] = 'image/svg+xml'; | |
$mimes['svgz'] = 'image/svg+xml'; | |
return $mimes; | |
} else { | |
return $mimes; | |
} | |
} | |
add_filter( 'upload_mimes', 'bodhi_svgs_upload_mimes', 99 ); | |
/** | |
* Check Mime Types | |
*/ | |
function bodhi_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', 'bodhi_svgs_upload_check', 10, 4 ); | |
// ############### FINAL SVG NO WORDPRESS ############### | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment