user roles – ‘upload_mimes’ filter seems to be restricting viewing/downloading as well

Question

I am trying to allow administrators to upload SVG files using upload_mimes filter.

function custom_upload_mimes( $mimes ) {

    // Allow additional mime types for administrators
    if( current_user_can('administrator') ) {
        $mimes['svg'] = 'image/svg+xml';
    }

    return $mimes;
}
add_filter( 'upload_mimes', 'custom_uplaod_mimes' );

It works well, however it seems to be limiting the viewing/downloading of those mime types as well. For example if an administrator uploads a site logo in SVG format, only administrators can see it. Logged out visitors only see blank image (SVG is not loading). If I remove the current_user_can condition, it works well.

Is this the correct behavior of this filter? Is there an upload-only alternative?

0
Kristian Filo 5 months 2022-07-15T00:59:25-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse