wppaste
WordPress

wp_installing( bool $is_installing = null ): bool

Since
4.4.0
Source
wp-includes/load.php:1633

Toggles or reports whether WordPress is currently running in installation mode by reading a static flag seeded from the WP_INSTALLING constant. Passing true or false overrides that flag for the rest of the request and hands back whatever state was in effect before the change, not the new one. Several core functions, including get_option(), add_option(), and delete_transient(), call it internally to skip normal caching while WordPress is being installed or upgraded, so flipping it by hand outside of that context can change how those functions behave for the rest of the request.

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.

Compatibility

WordPress
since 4.4.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

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 value

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.

Code examples

Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.

Check whether the current request is running in WordPress installation mode

A quick status check useful when a plugin needs to behave differently while the site is being set up.

$status = wp_installing();

printf(
	'wp_installing() currently reports: %s',
	esc_html( var_export( $status, true ) )
);

On a normal, already-installed site with WP_INSTALLING undefined, this prints false.

Temporarily flip installation mode and read back the previous state

Demonstrates that passing a value both sets the flag and returns the value it held immediately before the change.

$previous = wp_installing( true );
echo 'State before the change: ' . esc_html( var_export( $previous, true ) ) . "\n";

$current = wp_installing();
echo 'State after setting to true: ' . esc_html( var_export( $current, true ) ) . "\n";

$restored = wp_installing( false );
echo 'State restored to: ' . esc_html( var_export( $restored, true ) ) . "\n";

Always set the flag back to its original value in the same request, since it is stored in a static variable that persists for every subsequent call.

Common problems and fixes · 4

Why does wp_installing() return true even though I never called it with a parameter?

The function seeds its internal static flag from the WP_INSTALLING constant the first time it runs, before it ever looks at the $is_installing argument. If something earlier in the request (wp-config.php, the installer, or an upgrade script) defines WP_INSTALLING as true, every later call reports true until code explicitly passes false.

Why did my call to wp_installing( false ) seem to do nothing?

Once the static $installing variable has been initialized, further calls to wp_installing() without an argument just return the stored value, they never re-check the WP_INSTALLING constant. If another part of the request already flipped the flag back to true after your call, or ran before it, your false gets overwritten.

Why does the value I passed in never show up as the return value?

The source explicitly stores the old value before overwriting it, then returns that old value: $old_installing = $installing; $installing = $is_installing; return (bool) $old_installing;. So wp_installing( true ) never returns true, it returns whatever the flag was before your call.

Why do get_option() and delete_transient() behave inconsistently when installation mode is on?

Those functions (and others listed as callers of wp_installing()) branch on this flag specifically to skip the object cache and alloptions handling while WordPress is installing, since the options table and cache may not be reliable yet. Turning the flag on outside of an actual install or upgrade context reproduces that uncached behavior unexpectedly.

Alternatives and related functions

wp_doing_ajax
When you need to detect whether the current request is an admin-ajax.php call rather than whether WordPress is being installed.
wp_doing_cron
When the check you actually need is whether the code is executing during a WP-Cron event.
is_multisite
When the behavior you want to branch on depends on network configuration rather than install state.

Performance profile

How much work a call to wp_installing() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
8–15

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 17.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
49

49 places in core call this, so the cost is paid more often than your own code shows.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_installing() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always8–15none

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 17 instructions, 8–15 executed per call, 3 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Used by · 49

Show all 49

Source code

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

Introduced in 4.4.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/load.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.