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

onl*_*724 0 php wordpress file-upload

在我的 WordPress 网站上,超级管理员用户最多可以上传 256 MB,但编辑器用户最多只能上传 2 MB。如何增加呢?

onl*_*724 5

我的这段代码的问题已经解决了。

/**
* 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 );
Run Code Online (Sandbox Code Playgroud)

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