wppaste
WordPress

is_blog_installed(): bool

Since
2.1.0
Source
wp-includes/functions.php:1766
Determines whether WordPress is already installed.

Description

The cache will be checked first. If you have a cache plugin, which saves the cache values, then this will work. If you use the default WordPress cache, and the database goes away, then you might have problems.

Checks for the 'siteurl' option for whether WordPress is installed.

For more information on this and similar theme functions, check out the https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags article in the Theme Developer Handbook.

Compatibility

WordPress
since 2.1.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.

Return value

bool
Whether the site is already installed.

Performance profile

How much work a call to is_blog_installed() 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
Heavy

Reaches the database via ->get_var().

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
6–55

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
3

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

What it touches

  • cacheobject cachewp_cache_get()called directly
  • sqldatabase query->get_var()called directly
  • hookthird-party callbacksapply_filters()one call below is_blog_installed()

Further down the call graph this can also reach query, option, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 9 distinct outcomes

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

WhenInstructionsCalls it makes
wp_cache_get()6wp_cache_get()
!wp_cache_get() && wp_installing() && isset($alloptions)26–28wp_cache_get(), ->suppress_errors(), wp_installing(), ->suppress_errors(), wp_cache_set()
!wp_cache_get() && !wp_installing() && isset($alloptions)29–31wp_cache_get(), ->suppress_errors(), wp_installing(), wp_load_alloptions(), ->suppress_errors(), wp_cache_set()
!wp_cache_get() && wp_installing() && !isset($alloptions)34–36wp_cache_get(), ->suppress_errors(), wp_installing(), ->get_var(), ->suppress_errors(), wp_cache_set()
!wp_cache_get() && !wp_installing() && !isset($alloptions)37–39wp_cache_get(), ->suppress_errors(), wp_installing(), wp_load_alloptions(), ->get_var(), ->suppress_errors(), wp_cache_set()
!wp_cache_get() && wp_installing() && isset($alloptions) && !$alloptions && !defined('WP_REPAIRING')43–44wp_cache_get(), ->suppress_errors(), wp_installing(), ->suppress_errors(), wp_cache_set(), ->suppress_errors(), ->tables(), ->suppress_errors(), wp_cache_set()
!wp_cache_get() && !wp_installing() && isset($alloptions) && !$alloptions && !defined('WP_REPAIRING')46–47wp_cache_get(), ->suppress_errors(), wp_installing(), wp_load_alloptions(), ->suppress_errors(), wp_cache_set(), ->suppress_errors(), ->tables(), ->suppress_errors(), wp_cache_set()
!wp_cache_get() && wp_installing() && !isset($alloptions) && !$alloptions && !defined('WP_REPAIRING')51–52wp_cache_get(), ->suppress_errors(), wp_installing(), ->get_var(), ->suppress_errors(), wp_cache_set(), ->suppress_errors(), ->tables(), ->suppress_errors(), wp_cache_set()
!wp_cache_get() && !wp_installing() && !isset($alloptions) && !$alloptions && !defined('WP_REPAIRING')54–55wp_cache_get(), ->suppress_errors(), wp_installing(), wp_load_alloptions(), ->get_var(), ->suppress_errors(), wp_cache_set(), ->suppress_errors(), ->tables(), ->suppress_errors(), wp_cache_set()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 98 instructions, 6–55 executed per call, 15 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.

Uses · 7

Used by · 3

Source code

function is_blog_installed() {	global $wpdb; 	/*	 * Check cache first. If options table goes away and we have true	 * cached, oh well.	 */	if ( wp_cache_get( 'is_blog_installed' ) ) {		return true;	} 	$suppress = $wpdb->suppress_errors(); 	if ( ! wp_installing() ) {		$alloptions = wp_load_alloptions();	} 	// If siteurl is not set to autoload, check it specifically.	if ( ! isset( $alloptions['siteurl'] ) ) {		$installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );	} else {		$installed = $alloptions['siteurl'];	} 	$wpdb->suppress_errors( $suppress ); 	$installed = ! empty( $installed );	wp_cache_set( 'is_blog_installed', $installed ); 	if ( $installed ) {		return true;	} 	// If visiting repair.php, return true and let it take over.	if ( defined( 'WP_REPAIRING' ) ) {		return true;	} 	$suppress = $wpdb->suppress_errors(); 	/*	 * Loop over the WP tables. If none exist, then scratch installation is allowed.	 * If one or more exist, suggest table repair since we got here because the	 * options table could not be accessed.	 */	$wp_tables = $wpdb->tables();	foreach ( $wp_tables as $table ) {		// The existence of custom user tables shouldn't suggest an unwise state or prevent a clean installation.		if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE === $table ) {			continue;		} 		if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE === $table ) {			continue;		} 		$described_table = $wpdb->get_results( "DESCRIBE $table;" );		if (			( ! $described_table && empty( $wpdb->last_error ) ) ||			( is_array( $described_table ) && 0 === count( $described_table ) )		) {			continue;		} 		// One or more tables exist. This is not good. 		wp_load_translations_early(); 		// Die with a DB error.		$wpdb->error = sprintf(			/* translators: %s: Database repair URL. */			__( 'One or more database tables are unavailable. The database may need to be <a href="%s">repaired</a>.' ),			'maint/repair.php?referrer=is_blog_installed'		); 		dead_db();	} 	$wpdb->suppress_errors( $suppress );

Changelog

Introduced in 2.1.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 6.7.7 tag, from src/wp-includes/functions.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.