函数文档

ms_file_constants()

💡 云策文档标注

概述

ms_file_constants() 函数用于定义 WordPress 多站点(Multisite)文件常量,主要用于向后兼容旧版文件服务机制。

关键要点

  • 定义两个可选常量:WPMU_SENDFILE 和 WPMU_ACCEL_REDIRECT,用于支持 X-Sendfile 和 X-Accel-Redirect 头。
  • 这些常量默认设置为 false,仅在未定义时进行定义,确保兼容性。
  • 函数自 WordPress 3.0.0 版本引入,与 ms-files.php 和 blogs.php 等旧文件服务相关。

代码示例

function ms_file_constants() {
	/**
	 * Optional support for X-Sendfile header
	 *
	 * @since 3.0.0
	 */
	if ( ! defined( 'WPMU_SENDFILE' ) ) {
		define( 'WPMU_SENDFILE', false );
	}

	/**
	 * Optional support for X-Accel-Redirect header
	 *
	 * @since 3.0.0
	 */
	if ( ! defined( 'WPMU_ACCEL_REDIRECT' ) ) {
		define( 'WPMU_ACCEL_REDIRECT', false );
	}
}

注意事项

此函数主要用于多站点环境,处理旧版文件服务兼容性,开发者通常无需直接调用,但需了解其常量定义以避免冲突。


📄 原文内容

Defines Multisite file constants.

Description

Exists for backward compatibility with legacy file-serving through wp-includes/ms-files.php (wp-content/blogs.php in MU).

Source

function ms_file_constants() {
	/**
	 * Optional support for X-Sendfile header
	 *
	 * @since 3.0.0
	 */
	if ( ! defined( 'WPMU_SENDFILE' ) ) {
		define( 'WPMU_SENDFILE', false );
	}

	/**
	 * Optional support for X-Accel-Redirect header
	 *
	 * @since 3.0.0
	 */
	if ( ! defined( 'WPMU_ACCEL_REDIRECT' ) ) {
		define( 'WPMU_ACCEL_REDIRECT', false );
	}
}

Changelog

Version Description
3.0.0 Introduced.