/**
* Snippet Name: Enables SVG and SVGZ file uploads
* Snippet Author: coding-bunny.com
* Description: Enables SVG and SVGZ file uploads for admins to ensure safer file handling.
*/
function cb_allow_svg_uploads( $file_types ) {
// Only allow admins to upload SVG files for security
if ( current_user_can( 'administrator' ) ) {
// Define allowed SVG file types
$new_filetypes = array(
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml',
);
// Merge only new file types that are not already in the allowed list
$file_types = array_merge( $file_types, array_diff_key( $new_filetypes, $file_types ) );
}
return $file_types;
}
// Hook into 'upload_mimes' to add new file types
add_action( 'upload_mimes', 'cb_allow_svg_uploads' );
Enables SVG and SVGZ file uploads
Enables SVG and SVGZ file uploads for admins to ensure safer file handling.