函数文档

display_space_usage()

💡 云策文档标注

概述

display_space_usage() 函数用于显示当前站点已使用的磁盘空间量,并计算使用百分比。该函数在 WordPress 核心中未被使用。

关键要点

  • 函数功能:计算并显示当前站点的磁盘空间使用情况,包括已用空间、允许空间和使用百分比。
  • 依赖函数:调用 get_space_allowed() 获取上传配额,get_space_used() 获取已用空间,size_format() 格式化空间大小。
  • 核心状态:此函数在 WordPress 核心中未被使用,可能用于多站点环境或自定义功能。
  • 引入版本:从 WordPress MU 3.0.0 版本引入。

代码示例

function display_space_usage() {
    $space_allowed = get_space_allowed();
    $space_used    = get_space_used();

    $percent_used = ( $space_used / $space_allowed ) * 100;

    $space = size_format( $space_allowed * MB_IN_BYTES );
}

📄 原文内容

Displays the amount of disk space used by the current site. Not used in core.

Source

function display_space_usage() {
$space_allowed = get_space_allowed();
$space_used = get_space_used();

$percent_used = ( $space_used / $space_allowed ) * 100;

$space = size_format( $space_allowed * MB_IN_BYTES );
?>
<strong>

</strong>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-admin/includes/ms.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/ms.php#L255">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/ms.php#L255-L270">View on GitHub</a></p></section>

<section class="wp-block-wporg-code-reference-related" data-nosnippet="true"><h2 id="related" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#related">Related</a></h2> <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table" id="uses"><figure class="wp-block-table "><table><thead><tr><th scope="col">Uses</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/size_format/">size_format()</a><code>wp-includes/functions.php

Converts a number of bytes to the largest unit the bytes will fit into.

get_space_allowed()wp-includes/ms-functions.php

Returns the upload quota for the current blog.

get_space_used()wp-includes/ms-functions.php

Returns the space used by the current site.

__()wp-includes/l10n.php

Retrieves the translation of $text.

Show 1 moreShow less

Changelog

Version Description
MU (3.0.0) Introduced.