How To Temporarily Allow SVG File Uploads In Divi For Admin Users Only - Tutorial by Pee-Aye Creative
Wed Feb 07 2024 19:58:22 GMT+0000 (Coordinated Universal Time)
Saved by
@mraimondi3
/**
* Allow SVG
*
* @param $mimes
*
* @return mixed
*/
if (!function_exists('pac_da_mime_types')):
function pac_da_mime_types($mimes)
{
$mimes['svg'] = 'image/svg+xml';
$mimes['svgz'] = 'image/svg+xml';
return $mimes;
}
endif;
/**
* Fixes the issue in WordPress 4.7.1 being unable to correctly identify SVGs
*
* @param $data
* @param $file
* @param $filename
* @param $mimes
*
* @return array|mixed|null
*/
if (!function_exists('pac_da_fix_mime_type_svg')):
function pac_da_fix_mime_type_svg($data = null, $file = null, $filename = null, $mimes = null)
{
$ext = isset($data['ext']) ? $data['ext'] : '';
if (strlen($ext) < 1) {
$exploded = explode('.', $filename);
$ext = strtolower(end($exploded));
}
if ('svg' === $ext) {
$data['type'] = 'image/svg+xml';
$data['ext'] = 'svg';
} elseif ('svgz' === $ext) {
$data['type'] = 'image/svg+xml';
$data['ext'] = 'svgz';
}
return $data;
}
endif;
/**
* Allow SVG To Upload From Admin Side Only To Specific Roles
*
* @return void
*/
if (!function_exists('pac_da_allow_svg')):
function pac_da_allow_svg()
{
if (current_user_can('administrator')) {
add_filter('upload_mimes', 'pac_da_mime_types');
add_filter('wp_check_filetype_and_ext', 'pac_da_fix_mime_type_svg', 75, 4);
}
}
add_action('admin_init', 'pac_da_allow_svg');
endif;
content_copyCOPY
https://www.peeayecreative.com/how-to-temporarily-allow-svg-file-uploads-in-divi-for-admin-users-only/
Comments