暗区突围Ray直装官网,暗区突围国际服下载官方正版
发布时间:2025-10-28 06:32:03 作者:玩站小弟
我要评论凋谢注册的度差的文WordPress站点,艰深都市凭证差距品级的距用件规巨细用户脚色来给予差距的权限。文件上传功能便是户脚一个比力罕用的功能,那末,色可上传暗区突围Ray直装官网若何限度差距用户脚色可上传的范及文件规范及巨细呢?下面倡萌就来说说这个下场。让用户具备上传文件的度差的文暗区突围国际服下载官方正版权限默认情景下,有些用户是距用件规巨细不应承上传文件的,你可能在主题的户脚 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 定位到那边,距用件规巨细你就会看到详细的户脚暗区突围体验服下载文件规范: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, ) ); } => 的前面为格式,前面为格式形貌。色可上传假如你要防止上传其中的范及某些规范,可能参考下面的暗区突围ray例子:将下面的代码削减到主题的 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[格式]); 样例削减即可。假如你仅仅惟独要应承用户上传多少种规范而已经,还可能经由下面的暗区突围ray直装教程更简洁的措施,代码削减到主题的 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[格式]=形貌; 即可。限度用户上传的暗区突围Ray防封端口文件巨细同样在主题的 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自己艰深配置了应承上传的文件的最概况积,以是暗区突围ray直装怎么下载在这里配置需要思考到这点。限度差距用户脚色可上传的文件规范及巨细着实下面已经给出了限度规范以及巨细的措施,要凭证差距用户脚色来限度,惟独要削减脚色分说代码即可。暗区突围RAY官网倡萌举个综合的例子://差距用户上传的规范 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站点,艰深都市凭证差距品级的距用件规巨细用户脚色来给予差距的权限。文件上传功能便是户脚一个比力罕用的功能
,那末,色可上传暗区突围Ray直装官网若何限度差距用户脚色可上传的范及文件规范及巨细呢
?下面倡萌就来说说这个下场。
让用户具备上传文件的度差的文暗区突围国际服下载官方正版权限
默认情景下 ,有些用户是距用件规巨细不应承上传文件的,你可能在主题的户脚 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 定位到那边,距用件规巨细你就会看到详细的户脚暗区突围体验服下载文件规范:
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, ) ); }
=> 的前面为格式,前面为格式形貌。色可上传假如你要防止上传其中的范及某些规范,可能参考下面的暗区突围ray例子:
将下面的代码削减到主题的 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[格式]); 样例削减即可。
假如你仅仅惟独要应承用户上传多少种规范而已经,还可能经由下面的暗区突围ray直装教程更简洁的措施,代码削减到主题的 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[格式]=形貌; 即可。
限度用户上传的暗区突围Ray防封端口文件巨细
同样在主题的 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自己艰深配置了应承上传的文件的最概况积,以是暗区突围ray直装怎么下载在这里配置需要思考到这点
。
限度差距用户脚色可上传的文件规范及巨细
着实下面已经给出了限度规范以及巨细的措施
,要凭证差距用户脚色来限度
,惟独要削减脚色分说代码即可。暗区突围RAY官网倡萌举个综合的例子