钩子文档

enable_maintenance_mode

💡 云策文档标注

概述

enable_maintenance_mode 是一个 WordPress 过滤器,用于控制是否启用维护模式。它允许插件在非 Web 运行时干预维护模式的激活状态。

关键要点

  • 过滤器名称:enable_maintenance_mode
  • 作用:决定是否启用维护模式,返回 true 则激活维护模式并终止请求,返回 false 则允许请求继续处理
  • 参数:$enable_checks(布尔值,默认 true)和 $upgrading(时间戳,来自 .maintenance 文件)
  • 相关函数:wp_is_maintenance_mode() 用于检查维护模式是否启用
  • 引入版本:WordPress 4.6.0

代码示例

if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
    // 代码逻辑
}

📄 原文内容

Filters whether to enable maintenance mode.

Description

This filter runs before it can be used by plugins. It is designed for non-web runtimes. If this filter returns true, maintenance mode will be active and the request will end. If false, the request will be allowed to continue processing even if maintenance mode should be active.

Parameters

$enable_checksbool
Whether to enable maintenance mode. Default true.
$upgradingint
The timestamp set in the .maintenance file.

Source

if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {

Changelog

Version Description
4.6.0 Introduced.