函数文档

get_space_allowed()

💡 云策文档标注

概述

get_space_allowed() 函数用于获取当前博客的上传配额(以兆字节为单位)。它通过检查博客选项和站点选项来获取配额值,并提供一个过滤器钩子以允许自定义。

关键要点

  • 返回当前博客的上传配额,单位为兆字节(MB)。
  • 首先尝试从 get_option('blog_upload_space') 获取配额,如果无效则回退到 get_site_option('blog_upload_space')。
  • 如果以上选项均无效,默认返回 100 MB。
  • 提供 apply_filters('get_space_allowed', $space_allowed) 钩子,允许开发者过滤配额值。
  • 该函数在 WordPress 多站点环境中常用,用于管理上传空间。

代码示例

function get_space_allowed() {
    $space_allowed = get_option( 'blog_upload_space' );

    if ( ! is_numeric( $space_allowed ) ) {
        $space_allowed = get_site_option( 'blog_upload_space' );
    }

    if ( ! is_numeric( $space_allowed ) ) {
        $space_allowed = 100;
    }

    /**
     * Filters the upload quota for the current site.
     *
     * @since 3.7.0
     *
     * @param int $space_allowed Upload quota in megabytes for the current blog.
     */
    return apply_filters( 'get_space_allowed', $space_allowed );
}

📄 原文内容

Returns the upload quota for the current blog.

Return

int Quota in megabytes.

Source

function get_space_allowed() {
	$space_allowed = get_option( 'blog_upload_space' );

	if ( ! is_numeric( $space_allowed ) ) {
		$space_allowed = get_site_option( 'blog_upload_space' );
	}

	if ( ! is_numeric( $space_allowed ) ) {
		$space_allowed = 100;
	}

	/**
	 * Filters the upload quota for the current site.
	 *
	 * @since 3.7.0
	 *
	 * @param int $space_allowed Upload quota in megabytes for the current blog.
	 */
	return apply_filters( 'get_space_allowed', $space_allowed );
}

Hooks

apply_filters( ‘get_space_allowed’, int $space_allowed )

Filters the upload quota for the current site.

Changelog

Version Description
MU (3.0.0) Introduced.