最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

capabilities - Remove upload file types filter for admin

programmeradmin3浏览0评论

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.

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.

Share Improve this question edited Jun 4, 2019 at 15:45 dkangy asked Jun 3, 2019 at 16:54 dkangydkangy 114 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 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;
}

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/articles/new-wp-config-tweaks-you-probably-dont-know--wp-35396

发布评论

评论列表(0)

  1. 暂无评论