• Resolved ninsan

    (@jennyrigsjo)


    Hello,

    I am trying to restrict which file types can be uploaded by non-admin users. I have the following code in a mu-plugin, but it seemingly has no effect on which file types can be uploaded by users on their frontend WPUM account page (for example, I can still upload ‘.docx’ files):

    add_filter('upload_mimes','jr_restrict_allowed_file_types');
    
    /**
     * Define a custom list of allowed file types for user uploads. Exclude admins.
     *
     * @param array $mime_types Array of allowed file types.
     * @return array The (modified) array of file types.
     */
    function jr_restrict_allowed_file_types($mime_types) {
    
        if (!current_user_can('administrator')) {
            $mime_types = array(
                'jpg|jpeg|jpe' => 'image/jpeg',
                'png' => 'image/png',
                'gif' => 'image/gif',
            );
        }
    
        return $mime_types;
    }

    Is there any way to restrict which file types can be uploaded on the WPUM user account page?

    Thanks. ??

    /jenny

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WP User Manager

    (@wpusermanager)

    Hey @jennyrigsjo you can set the ‘Allowed File Types’ for a WPUM File custom field, by editing the field then going to the Validation tab.

    This setting allows a comma separated lst of allowed file types, (i.e. jpg, gif, png, pdf)

    Thread Starter ninsan

    (@jennyrigsjo)

    @wpusermanager Hi, thanks so much! I can’t believe I didn’t think to check in the ‘custom fields’ part of the plugin’s admin menu before asking here (sorry). Thank you for taking the time to reply. ??

    /jenny

    Plugin Author WP User Manager

    (@wpusermanager)

    No problem ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to restrict allowed file types for user uploads?’ is closed to new replies.