get_upload_space_available()
云策文档标注
概述
get_upload_space_available() 函数用于确定当前博客的配额中是否还有剩余上传空间。它返回以字节为单位的可用上传空间大小。
关键要点
- 函数返回当前博客的可用上传空间字节数
- 适用于多站点环境,检查上传配额限制
- 与 get_space_allowed() 和 get_space_used() 等函数相关,用于空间管理
代码示例
function get_upload_space_available() {
$allowed = get_space_allowed();
if ( $allowed < 0 ) {
return 0;
}
$used = get_space_used();
if ( $used > $allowed ) {
return 0;
}
return $allowed - $used;
}注意事项
- 函数从 WordPress 3.0.0 版本引入
- 主要用于多站点环境,处理上传空间配额检查
- 返回值为整数,表示剩余空间字节数,若无空间则返回 0
原文内容
Determines if there is any upload space left in the current blog’s quota.
Source
function get_upload_space_available() {
$allowed = get_space_allowed();
if ( $allowed < 0 ) {
$allowed = 0;
}
$space_allowed = $allowed * MB_IN_BYTES;
if ( get_site_option( 'upload_space_check_disabled' ) ) {
return $space_allowed;
}
$space_used = get_space_used() * MB_IN_BYTES;
if ( ( $space_allowed - $space_used ) <= 0 ) {
return 0;
}
return $space_allowed - $space_used;
}
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |