function limit_upload_size($file)
{
// Set the desired file size limit
$file_size_limit = 1024; // 1MB in KB
// exclude admins
if (!current_user_can('manage_options')) { //如果不是管理员
$current_size = $file['size'];
$current_size = $current_size / 1024; //get size in KB
if ($current_size > $file_size_limit) {
$file['error'] = sprintf(__('ERROR: File size limit is %d KB.'), $file_size_limit);
}
}
return $file;
}
add_filter('wp_handle_upload_prefilter', 'limit_upload_size', 10, 1);
if (!current_user_can('manage_options')) { //如果不是管理员
add_filter('upload_size_limit', 'wpse_228300_change_upload_size');
}
function wpse_228300_change_upload_size()
{
return 1000 * 1024;
}
使用上述代码后:


评论区
发表新的留言
您可以留言提出您的疑问或建议。
您的留言得到回复时,会通过您填写的邮箱提醒您。