找到了这个,它可以工作,但要将10 MB限制更改为5 GB。
$upload_bytes_limit_reached = ( ( $filesize + $upload_bytes ) > ( 1024 * 1024 * 10 ) );
<小时>
add_filter( \'wp_handle_upload\', \'wpse47580_update_upload_stats\' );
function wpse47580_update_upload_stats( $args ) {
$size = filesize( $args[\'file\'] );
$user_id = get_current_user_id();
$upload_count = get_user_meta( $user_id, \'upload_count\', true );
$upload_bytes = get_user_meta( $user_id, \'upload_bytes\', true );
update_user_meta( $user_id, \'upload_count\', $upload_count + 1 );
update_user_meta( $user_id, \'upload_bytes\', $upload_bytes + $size );
}
此函数在上载文件之前运行
add_filter( \'wp_handle_upload_prefilter\', \'wpse47580_check_upload_limits\' );
function wpse47580_check_upload_limits( $file ) {
$user_id = get_current_user_id();
$upload_count = get_user_meta( $user_id, \'upload_count\', true );
$upload_bytes = get_user_meta( $user_id, \'upload_bytes\', true );
$filesize = $file[\'size\']; // bytes
$upload_bytes_limit_reached = ( ( $filesize + $upload_bytes ) > ( 1024 * 1024 * 10 ) );
$upload_count_limit_reached = ( $upload_count + 1 ) > 100;
if ( $upload_count_limit_reached || $upload_bytes_limit_reached )
$file[\'error\'] = \'Upload limit has been reached for this account!\';
return $file;
}
最合适的回答,由SO网友:Darren Cain 整理而成
我让它工作了。我删除了脚本的上半部分。不知道为什么它现在能工作,但测试了它,并做了我想要的。感谢您的帮助和支持。可以找到原始线程here, 对于那些感兴趣的人。
add_filter( \'wp_handle_upload_prefilter\', \'wpse47580_check_upload_limits\' );
function wpse47580_check_upload_limits( $file ) {
$user_id = get_current_user_id();
$upload_bytes = get_user_meta( $user_id, \'upload_bytes\', true );
$filesize = $file[\'size\']; // bytes
$upload_bytes_limit_reached = ( ( $filesize + $upload_bytes ) > ( GB_IN_BYTES * 5 ) );
if ( $upload_bytes_limit_reached )
$file[\'error\'] = \'Upload limit has been reached for this account!\';
return $file;
}