Last active
May 25, 2017 19:55
-
-
Save walshyb/9f4b23174fd96dfed1a5994e4d24e18e to your computer and use it in GitHub Desktop.
In WordPress, allow uploading of svgs through the Admin Panel to the media library if the current user is an administrator.
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 | |
function enable_svg_upload_if_admin($mimes) { | |
$current_user_roles = wp_get_current_user()->roles; // get roles of current user | |
// check if user is administrator and user is in the admin panel (not in the frontend) | |
if(in_array('administrator', $current_user_roles) && is_admin()) { | |
$mimes['svg'] = 'image/svg+xml'; | |
return $mimes; // if administrator, enable svg upload | |
} | |
return $mimes; // if not admin, keep default upload types | |
} | |
add_filter('upload_mimes', 'enable_svg_upload_if_admin'); // tell WordPress about enable_svg_upload_if_admin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment