函数文档

wp_installing()

💡 云策文档标注

概述

wp_installing() 函数用于检查或设置 WordPress 是否处于“安装”模式。它基于 WP_INSTALLING 常量或传入参数来返回或更新安装状态。

关键要点

  • 函数 wp_installing() 可检查或设置 WordPress 的安装模式状态。
  • 如果定义了 WP_INSTALLING 常量,函数默认返回 true 表示正在安装。
  • 参数 $is_installing 可选:传入 true 或 false 可设置安装模式;省略则仅获取当前状态。
  • 返回值:当仅获取状态时,返回布尔值表示是否在安装;当设置状态时,返回设置前的状态。

代码示例

function wp_installing( $is_installing = null ) {
	static $installing = null;

	// Support for the `WP_INSTALLING` constant, defined before WP is loaded.
	if ( is_null( $installing ) ) {
		$installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING;
	}

	if ( ! is_null( $is_installing ) ) {
		$old_installing = $installing;
		$installing     = $is_installing;

		return (bool) $old_installing;
	}

	return (bool) $installing;
}

📄 原文内容

Checks or sets whether WordPress is in “installation” mode.

Description

If the WP_INSTALLING constant is defined during the bootstrap, wp_installing() will default to true.

Parameters

$is_installingbooloptional
True to set WP into Installing mode, false to turn Installing mode off.
Omit this parameter if you only want to fetch the current status.

Default:null

Return

bool True if WP is installing, otherwise false. When a $is_installing is passed, the function will report whether WP was in installing mode prior to the change to $is_installing.

Source

function wp_installing( $is_installing = null ) {
	static $installing = null;

	// Support for the `WP_INSTALLING` constant, defined before WP is loaded.
	if ( is_null( $installing ) ) {
		$installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING;
	}

	if ( ! is_null( $is_installing ) ) {
		$old_installing = $installing;
		$installing     = $is_installing;

		return (bool) $old_installing;
	}

	return (bool) $installing;
}

Changelog

Version Description
4.4.0 Introduced.