Created
April 16, 2025 20:07
-
-
Save osbre/36f250c5b8cda02f94c5e2b9979fffc5 to your computer and use it in GitHub Desktop.
WordPress / ClassicPress plugin to enable SVG uploads for admins.
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 | |
/** | |
* 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