WordPress 限制不同用户角色可上传的文件类型及大小【抖音免费10000赞活人】

  发布时间:2025-11-03 04:43:32   作者:玩站小弟   我要评论
开放注册的限型及WordPress站点,一般都会根据不同等级的同用用户角色来赋予不同的权限。文件上传功能就是户角一个比较常用的功能,那么,色可上传抖音免费10000赞活人如何限制不同用户角色可上传的限型及文件类型及大小呢?下面倡萌就来说说这个问题。让用户拥有上传文件的同用KS一秒5000赞权限默认情况下,有些用户是户角不允许上传文件的,你可以在主题的色可上传 functions.php 添加下面的代码://允许用户投稿时上传文件 if ( current_user_can(contributor) && !current_user_can(upload_files) ) add_action(admin_init, allow_contributor_uploads); function allow_contributor_uploads() { $contributor = get_role(contributor); $contributor->add_cap(upload_files); } 上面的代码就是给 contributor 这个用户角色添加了 upload_files (上传文件)的权限。限制用户上传文件的限型及类型首先,大家可以先了解一下 WordPress 默认允许上传的同用文件类型,打开WordPress的户角 /wp-includes/functions.php 文件,然后搜索 function wp_get_mime_types 定位到那里,色可上传你就会看到详细的限型及抖音粉丝业务套餐0.1-1000万粉丝文件类型:function wp_get_mime_types() { // Accepted MIME types are set here as PCRE unless provided. return apply_filters( mime_types, array( // Image formats jpg|jpeg|jpe => image/jpeg, gif => image/gif, png => image/png, bmp => image/bmp, tif|tiff => image/tiff, ico => image/x-icon, // Video formats asf|asx|wax|wmv|wmx => video/asf, avi => video/avi, divx => video/divx, flv => video/x-flv, mov|qt => video/quicktime, mpeg|mpg|mpe => video/mpeg, mp4|m4v => video/mp4, ogv => video/ogg, mkv => video/x-matroska, // Text formats txt|asc|c|cc|h => text/plain, csv => text/csv, tsv => text/tab-separated-values, ics => text/calendar, rtx => text/richtext, css => text/css, htm|html => text/html, // Audio formats mp3|m4a|m4b => audio/mpeg, ra|ram => audio/x-realaudio, wav => audio/wav, ogg|oga => audio/ogg, mid|midi => audio/midi, wma => audio/wma, mka => audio/x-matroska, // Misc application formats rtf => application/rtf, js => application/javascript, pdf => application/pdf, swf => application/x-shockwave-flash, class => application/java, tar => application/x-tar, zip => application/zip, gz|gzip => application/x-gzip, rar => application/rar, 7z => application/x-7z-compressed, exe => application/x-msdownload, // MS Office formats doc => application/msword, pot|pps|ppt => application/vnd.ms-powerpoint, wri => application/vnd.ms-write, xla|xls|xlt|xlw => application/vnd.ms-excel, mdb => application/vnd.ms-access, mpp => application/vnd.ms-project, docx => application/vnd.openxmlformats-officedocument.wordprocessingml.document, docm => application/vnd.ms-word.document.macroEnabled.12, dotx => application/vnd.openxmlformats-officedocument.wordprocessingml.template, dotm => application/vnd.ms-word.template.macroEnabled.12, xlsx => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, xlsm => application/vnd.ms-excel.sheet.macroEnabled.12, xlsb => application/vnd.ms-excel.sheet.binary.macroEnabled.12, xltx => application/vnd.openxmlformats-officedocument.spreadsheetml.template, xltm => application/vnd.ms-excel.template.macroEnabled.12, xlam => application/vnd.ms-excel.addin.macroEnabled.12, pptx => application/vnd.openxmlformats-officedocument.presentationml.presentation, pptm => application/vnd.ms-powerpoint.presentation.macroEnabled.12, ppsx => application/vnd.openxmlformats-officedocument.presentationml.slideshow, ppsm => application/vnd.ms-powerpoint.slideshow.macroEnabled.12, potx => application/vnd.openxmlformats-officedocument.presentationml.template, potm => application/vnd.ms-powerpoint.template.macroEnabled.12, ppam => application/vnd.ms-powerpoint.addin.macroEnabled.12, sldx => application/vnd.openxmlformats-officedocument.presentationml.slide, sldm => application/vnd.ms-powerpoint.slide.macroEnabled.12, onetoc|onetoc2|onetmp|onepkg => application/onenote, // OpenOffice formats odt => application/vnd.oasis.opendocument.text, odp => application/vnd.oasis.opendocument.presentation, ods => application/vnd.oasis.opendocument.spreadsheet, odg => application/vnd.oasis.opendocument.graphics, odc => application/vnd.oasis.opendocument.chart, odb => application/vnd.oasis.opendocument.database, odf => application/vnd.oasis.opendocument.formula, // WordPerfect formats wp|wpd => application/wordperfect, ) ); } => 的前面为格式,后面为格式描述。同用如果你要禁止上传其中的户角某些类型,可以参考下面的抖音二十四小时下单平台例子:将下面的代码添加到主题的 functions.php 文件://禁止上传avi和mp4格式的文件 add_filter(upload_mimes, custom_upload_mimes); function custom_upload_mimes ( $existing_mimes=array() ) { unset ($existing_mimes[avi]); unset ($existing_mimes[mp4]); return $existing_mimes; } 如果你还要禁止更多,可以按照 unset ($existing_mimes[格式]);  样例添加即可。如果你仅仅只需要允许用户上传几种类型而已,还可以通过下面的免费领取1000个快手赞更简洁的方法,代码添加到主题的 functions.php 文件://只允许上传图片文件 add_filter(upload_mimes, custom_upload_mimes); function custom_upload_mimes ( $existing_mimes=array() ) { unset ($existing_mimes);//禁止上传任何文件 $existing_mimes[jpg|jpeg|gif|png]=image/image;//允许用户上传jpg,gif,png文件 return $existing_mimes; } 如果你还要允许上传其他格式,重复使用 $existing_mimes[格式]=描述;  即可。限制用户上传的一米100赞快手文件大小同样在主题的 functions.php 文件中,添加下面的代码://限制上传文件的最大体积 function max_up_size() { return 500*1024; // 500 kb } add_filter(upload_size_limit, max_up_size); 上面的例子是限制所有用户上传的文件的最大体积为 500 kb (1M =1024*1024)。注意:主机空间和WordPress本身一般设置了允许上传的文件的最大体积,所以在这里设置需要考虑到这点。24小时点赞自助服务限制不同用户角色可上传的文件类型及大小其实上面已经给出了限制类型和大小的方法,要根据不同用户角色来限制,只需要添加角色判断代码即可。KS一秒5000赞倡萌举个综合的例子://不同用户上传的类型 function custom_upload_mimes ( $existing_mimes=array() ) { unset ($existing_mimes);//禁止上传任何文件 if( current_user_can( publish_posts ) && !current_user_can( publish_pages ) ) { //允许作者(Author)上传的类型 $existing_mimes[jpg|jpeg|gif|png]=image/image;//允许用户上传jpg,gif,png文件 $existing_mimes[zip]=application/zip; //允许用户上传zip压缩包 $existing_mimes[pdf]=application/pdf; //允许用户上传pdf文件 }elseif( current_user_can( edit_posts ) && !current_user_can( publish_posts ) ) { //允许投稿者(Contributor)上传的类型 $existing_mimes[jpg|jpeg|gif|png]=image/image; $existing_mimes[pdf]=application/pdf; }else{ //其他用户角色上传的类型 $existing_mimes[jpg|jpeg|gif|png]=image/image; } return $existing_mimes; } //不同用户上传的大小 function max_up_size() { if( current_user_can( publish_posts ) && !current_user_can( publish_pages ) ) { return 2048*1024; // 允许作者(Author)上传 2M }elseif( current_user_can( edit_posts ) && !current_user_can( publish_posts ) ) { return 1024*1024; // 允许投稿者(Contributor)上传 1M }else{ return 500*1024; // 其他用户角色上传 500 kb } } //只对非管理员执行这两个函数(即:对管理员不生效) if( !current_user_can( manage_options ) ) { add_filter(upload_mimes, custom_upload_mimes); add_filter(upload_size_limit, max_up_size); }。

开放注册的限型及WordPress站点 ,一般都会根据不同等级的同用用户角色来赋予不同的权限。文件上传功能就是户角一个比较常用的功能 ,那么  ,色可上传抖音免费10000赞活人如何限制不同用户角色可上传的限型及文件类型及大小呢?下面倡萌就来说说这个问题 。

让用户拥有上传文件的同用KS一秒5000赞权限

默认情况下,有些用户是户角不允许上传文件的 ,你可以在主题的色可上传 functions.php 添加下面的代码 :

WordPress 限制不同用户角色可上传的文件类型及大小【抖音免费10000赞活人】

//允许用户投稿时上传文件 if ( current_user_can(contributor) && !current_user_can(upload_files) ) add_action(admin_init, allow_contributor_uploads); function allow_contributor_uploads() { $contributor = get_role(contributor); $contributor->add_cap(upload_files); }

上面的代码就是给 contributor 这个用户角色添加了 upload_files (上传文件)的权限 。

限制用户上传文件的限型及类型

首先 ,大家可以先了解一下 WordPress 默认允许上传的同用文件类型,打开WordPress的户角 /wp-includes/functions.php 文件 ,然后搜索 function wp_get_mime_types 定位到那里  ,色可上传你就会看到详细的限型及抖音粉丝业务套餐0.1-1000万粉丝文件类型:

function wp_get_mime_types() { // Accepted MIME types are set here as PCRE unless provided. return apply_filters( mime_types, array( // Image formats jpg|jpeg|jpe => image/jpeg, gif => image/gif, png => image/png, bmp => image/bmp, tif|tiff => image/tiff, ico => image/x-icon, // Video formats asf|asx|wax|wmv|wmx => video/asf, avi => video/avi, divx => video/divx, flv => video/x-flv, mov|qt => video/quicktime, mpeg|mpg|mpe => video/mpeg, mp4|m4v => video/mp4, ogv => video/ogg, mkv => video/x-matroska, // Text formats txt|asc|c|cc|h => text/plain, csv => text/csv, tsv => text/tab-separated-values, ics => text/calendar, rtx => text/richtext, css => text/css, htm|html => text/html, // Audio formats mp3|m4a|m4b => audio/mpeg, ra|ram => audio/x-realaudio, wav => audio/wav, ogg|oga => audio/ogg, mid|midi => audio/midi, wma => audio/wma, mka => audio/x-matroska, // Misc application formats rtf => application/rtf, js => application/javascript, pdf => application/pdf, swf => application/x-shockwave-flash, class => application/java, tar => application/x-tar, zip => application/zip, gz|gzip => application/x-gzip, rar => application/rar, 7z => application/x-7z-compressed, exe => application/x-msdownload, // MS Office formats doc => application/msword, pot|pps|ppt => application/vnd.ms-powerpoint, wri => application/vnd.ms-write, xla|xls|xlt|xlw => application/vnd.ms-excel, mdb => application/vnd.ms-access, mpp => application/vnd.ms-project, docx => application/vnd.openxmlformats-officedocument.wordprocessingml.document, docm => application/vnd.ms-word.document.macroEnabled.12, dotx => application/vnd.openxmlformats-officedocument.wordprocessingml.template, dotm => application/vnd.ms-word.template.macroEnabled.12, xlsx => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, xlsm => application/vnd.ms-excel.sheet.macroEnabled.12, xlsb => application/vnd.ms-excel.sheet.binary.macroEnabled.12, xltx => application/vnd.openxmlformats-officedocument.spreadsheetml.template, xltm => application/vnd.ms-excel.template.macroEnabled.12, xlam => application/vnd.ms-excel.addin.macroEnabled.12, pptx => application/vnd.openxmlformats-officedocument.presentationml.presentation, pptm => application/vnd.ms-powerpoint.presentation.macroEnabled.12, ppsx => application/vnd.openxmlformats-officedocument.presentationml.slideshow, ppsm => application/vnd.ms-powerpoint.slideshow.macroEnabled.12, potx => application/vnd.openxmlformats-officedocument.presentationml.template, potm => application/vnd.ms-powerpoint.template.macroEnabled.12, ppam => application/vnd.ms-powerpoint.addin.macroEnabled.12, sldx => application/vnd.openxmlformats-officedocument.presentationml.slide, sldm => application/vnd.ms-powerpoint.slide.macroEnabled.12, onetoc|onetoc2|onetmp|onepkg => application/onenote, // OpenOffice formats odt => application/vnd.oasis.opendocument.text, odp => application/vnd.oasis.opendocument.presentation, ods => application/vnd.oasis.opendocument.spreadsheet, odg => application/vnd.oasis.opendocument.graphics, odc => application/vnd.oasis.opendocument.chart, odb => application/vnd.oasis.opendocument.database, odf => application/vnd.oasis.opendocument.formula, // WordPerfect formats wp|wpd => application/wordperfect, ) ); }

=> 的前面为格式 ,后面为格式描述。同用如果你要禁止上传其中的户角某些类型 ,可以参考下面的抖音二十四小时下单平台例子 :

将下面的代码添加到主题的 functions.php 文件:

//禁止上传avi和mp4格式的文件 add_filter(upload_mimes, custom_upload_mimes); function custom_upload_mimes ( $existing_mimes=array() ) { unset ($existing_mimes[avi]); unset ($existing_mimes[mp4]); return $existing_mimes; }

如果你还要禁止更多 ,可以按照 unset ($existing_mimes[格式]);  样例添加即可 。

如果你仅仅只需要允许用户上传几种类型而已,还可以通过下面的免费领取1000个快手赞更简洁的方法,代码添加到主题的 functions.php 文件 :

//只允许上传图片文件 add_filter(upload_mimes, custom_upload_mimes); function custom_upload_mimes ( $existing_mimes=array() ) { unset ($existing_mimes);//禁止上传任何文件 $existing_mimes[jpg|jpeg|gif|png]=image/image;//允许用户上传jpg,gif,png文件 return $existing_mimes; }

如果你还要允许上传其他格式 ,重复使用 $existing_mimes[格式]=描述;  即可。

限制用户上传的一米100赞快手文件大小

同样在主题的 functions.php 文件中 ,添加下面的代码:

//限制上传文件的最大体积 function max_up_size() { return 500*1024; // 500 kb } add_filter(upload_size_limit, max_up_size);

上面的例子是限制所有用户上传的文件的最大体积为 500 kb (1M =1024*1024)。

注意:主机空间和WordPress本身一般设置了允许上传的文件的最大体积,所以在这里设置需要考虑到这点。24小时点赞自助服务

限制不同用户角色可上传的文件类型及大小

其实上面已经给出了限制类型和大小的方法,要根据不同用户角色来限制 ,只需要添加角色判断代码即可。KS一秒5000赞倡萌举个综合的例子 :

//不同用户上传的类型 function custom_upload_mimes ( $existing_mimes=array() ) { unset ($existing_mimes);//禁止上传任何文件 if( current_user_can( publish_posts ) && !current_user_can( publish_pages ) ) { //允许作者(Author)上传的类型 $existing_mimes[jpg|jpeg|gif|png]=image/image;//允许用户上传jpg,gif,png文件 $existing_mimes[zip]=application/zip; //允许用户上传zip压缩包 $existing_mimes[pdf]=application/pdf; //允许用户上传pdf文件 }elseif( current_user_can( edit_posts ) && !current_user_can( publish_posts ) ) { //允许投稿者(Contributor)上传的类型 $existing_mimes[jpg|jpeg|gif|png]=image/image; $existing_mimes[pdf]=application/pdf; }else{ //其他用户角色上传的类型 $existing_mimes[jpg|jpeg|gif|png]=image/image; } return $existing_mimes; } //不同用户上传的大小 function max_up_size() { if( current_user_can( publish_posts ) && !current_user_can( publish_pages ) ) { return 2048*1024; // 允许作者(Author)上传 2M }elseif( current_user_can( edit_posts ) && !current_user_can( publish_posts ) ) { return 1024*1024; // 允许投稿者(Contributor)上传 1M }else{ return 500*1024; // 其他用户角色上传 500 kb } } //只对非管理员执行这两个函数(即:对管理员不生效) if( !current_user_can( manage_options ) ) { add_filter(upload_mimes, custom_upload_mimes); add_filter(upload_size_limit, max_up_size); }

相关文章

  • 微软 New Bing 完美聊天机器人源码,支持 ChatGPT 提示词

    源码简介微软 New Bing 完美聊天机器人源码 ,支持 ChatGPT 提示词,拥有一致的 UI 体验,国内可用,基本兼容微软 Bing AI 所有功能这款聊天机器人不仅能够支持现有的开源提示词库,
    2025-11-03
  • 变异恐龙争霸战最新版

    变异恐龙争霸战最新版是一款深受玩家们喜爱的恐龙题材的动作冒险类游戏,玩家们在这里需要合理的布阵和技能搭配 ,通过与差异种类的恐龙进行战斗,探索新的地域 ,并开启新的玩法 。感受每一场爽快刺激的竞技对决 ,在不
    2025-11-03
  • 抖音点赞增粉,抖音点赞免费24小时在线 - 快手点赞评论播放量平台 - dy自助平台业务下单真人

    什么是购券乐  ?购券乐是一款卡券购物平台 ,为用户提供了更加便捷 、优惠的购物体验 。这款平台汇聚了众多知名品牌商家的卡券,用户可以通过选购卡券的方式来享受各类商品的优惠。同时,购券乐还提供了个性化的推荐服务
    2025-11-03
  • 高跟鞋向前冲正式版

    高跟鞋向前冲正式版是一款休闲益智的跑酷闯关手游 。玩家们不光可以踩着高跟鞋一路突飞猛进 ,还能迅速的在线跳跃 ,迅速的在这里穿越差异的障碍物和陷阱 ,游戏中完结更多的关卡任务就会收获大量奖励,这个过程一定要保
    2025-11-03
  • 宝塔面板最新8.0.0开心版企业功能免费

    程序介绍本脚本未加密,有没有后门大家自己看就知道了 ,仅仅将官方的脚本本地化了,未经任何修改,请放心使用 !本次脚本支持:Centos 7、Debian 、Ubuntu、Fedora!注意事项问:为什么企业
    2025-11-03
  • 仙灵修真最新版

    仙灵修真最新版是一款非常好玩的仙侠手游 ,游戏内容都是以经典的小说剧情改编而来的,游戏中你可以养萌宠,和萌宠一起并肩作战,急需要收集装备是资源,提升自己的战斗能力,升级自己的装备和材料 ,同时剧情也衔接的
    2025-11-03

最新评论