1

Does anyone know if there is a function to remove/bypass file types uploads filter (specifically for admins). I know there are plugins available but they often break or don't contain ALL the mime types I need to allow and to be completely honest I'm just tired of dealing with this constantly. I also know about the constant ALLOW_UNFILTERED_UPLOADS which I'm using currently, but eventually I need only for the admin to be able to upload without restriction. I'm not sure how to do this in config file. Tried searching for a resolution but only found for allowing specific file types.

0

This is example for only doc file for admin.

You are also add another file to avoid restriction for admin.

add_filter( 'wp_check_filetype_and_ext', 'file_and_ext_allow_for_user', 10, 4 );
function file_and_ext_allow_for_user( $types, $file, $filename, $mimes )
{
    if( is_admin() ){
        if( false !== strpos( $filename, '.doc' ) )
        {
            $types['ext'] = 'doc';
            $types['type'] = 'application/msword';
        }
    }

    return $types;
}
| improve this answer | |
  • Thanks. Hoping to avoid having to maintain a list of file types though and completely remove WordPress' MIME check altogether. I found this secure.wphackedhelp.com/blog/… searching last night but haven't tried it yet. – dkangy Jun 4 '19 at 15:08
0

Ok my mistake. I didn't realize setting ALLOW_UNFILTERED_UPLOADS=true ONLY applies to admins already. Which might explain why it was difficult to find an answer to my original question. Woops! Source: https://code.tutsplus.com/articles/new-wp-config-tweaks-you-probably-dont-know--wp-35396

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.