简体   繁体   English

如何增加 Wordpress 中特定用户角色的最大上传文件大小?

[英]How to increase max upload file size for specific user roles in Wordpress?

On my WordPress site, the Super Administrator user can upload up to 256 MB, but the editor users can only upload up 2 MB.在我的 WordPress 网站上,超级管理员用户最多可以上传 256 MB,但编辑器用户最多只能上传 2 MB。 How to increase it?如何增加呢?

My problem with this piece of code was solved.这段代码的问题解决了。

/**
* Filter the upload size limit for non-administrators.
*
* @param string $size Upload size limit (in bytes).
* @return int (maybe) Filtered size limit.
*/
function filter_site_upload_size_limit( $size ) {
    // Set the upload size limit to 10 MB for users lacking the 'manage_options' capability.
    if ( ! current_user_can( 'manage_options' ) ) {
        // 10 MB.
    $size = 1024 * 10000;
    }
    return $size;
}
add_filter( 'upload_size_limit', 'filter_site_upload_size_limit', 20 );

Source: https://developer.wordpress.org/reference/hooks/upload_size_limit/#user-contributed-notes来源: https ://developer.wordpress.org/reference/hooks/upload_size_limit/#user-contributed-notes

The short answer is that you can't increase it beyond the limits set by super user.简短的回答是您不能将其增加到超出超级用户设置的限制。 So, if you found 2MB as the maximum value, it would be the maximum set by admin.因此,如果您发现 2MB 作为最大值,则它将是管理员设置的最大值。

You can do this very easy for each site inside Network Admin>Sites.您可以非常轻松地为网络管理>站点中的每个站点执行此操作。 Select the site you want to edit and once on the settings page scroll all the way to the bottom.选择您要编辑的网站,然后在设置页面上一直滚动到底部。 You will see Upload limit setting.您将看到上传限制设置。 So if you as a superadmin created a site and need to have more upload limit you can do this.因此,如果您作为超级管理员创建了一个站点并且需要有更多的上传限制,您可以这样做。 For a role setting the code mentioned above works.对于角色设置,上述代码有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM