Skip to content

Instantly share code, notes, and snippets.

@osbre
Created April 16, 2025 20:07
Show Gist options
  • Save osbre/36f250c5b8cda02f94c5e2b9979fffc5 to your computer and use it in GitHub Desktop.
Save osbre/36f250c5b8cda02f94c5e2b9979fffc5 to your computer and use it in GitHub Desktop.
WordPress / ClassicPress plugin to enable SVG uploads for admins.
<?php
/**
* Plugin Name: SVG Upload Support
* Description: Allows SVG uploads for admins only.
* Version: 1.0
* Author: Ostap Brehin
* Author URI: https://ostapbrehin.com
*/
add_filter('upload_mimes', function ($mimes) {
if (current_user_can('manage_options')) {
$mimes['svg'] = 'image/svg+xml';
}
return $mimes;
});
add_filter('wp_check_filetype_and_ext', function ($data, $file, $filename, $mimes) {
if (!$data['type'] && current_user_can('manage_options') && preg_match('/\.svg$/i', $filename)) {
$data['type'] = 'image/svg+xml';
$data['ext'] = 'svg';
}
return $data;
}, 10, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment