wppaste
WordPress

install_blog( int $blog_id, string $blog_title = '' )

Since
MU (3.0.0)
Source
wp-includes/ms-deprecated.php:610
Install an empty blog.

Description

Creates the new blog tables and options. If calling this function directly, be sure to use switch_to_blog() first, so that $wpdb points to the new blog.

Compatibility

Deprecated in WordPress 5.1.0. Kept for back-compatibility; avoid it in new code.

WordPress
since MU (3.0.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

$blog_idint
The value returned by wp_insert_site().
$blog_titlestringoptional
The title of the new site.Default: ''

Performance profile

How much work a call to install_blog() 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_results().

Scaling
Constant

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

Instructions
100–147

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

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

What it touches

  • optionnetwork optionget_site_option()called directly
  • sqldatabase query->get_results()called directly
  • hookthird-party callbacksdo_action()one call below install_blog()
  • serializeserialisationmaybe_serialize()one call below install_blog()
  • cacheobject cachewp_cache_get()one call below install_blog()

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

What one call costs · 20 distinct outcomes

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

WhenInstructionsCalls it makes
!->get_results() && is_subdomain_install() && get_site_option()100_deprecated_function(), ->suppress_errors(), ->get_results(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), update_option(), update_option(), get_site_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
!->get_results() && is_subdomain_install() && !get_site_option()102_deprecated_function(), ->suppress_errors(), ->get_results(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), update_option(), update_option(), get_site_option(), get_network(), get_blog_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
->get_results() && is_subdomain_install() && get_site_option()113_deprecated_function(), ->suppress_errors(), ->get_results(), __(), __(), exit(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), update_option(), update_option(), get_site_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
->get_results() && is_subdomain_install() && !get_site_option()115_deprecated_function(), ->suppress_errors(), ->get_results(), __(), __(), exit(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), update_option(), update_option(), get_site_option(), get_network(), get_blog_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
!->get_results() && !is_subdomain_install() && get_site_option()122_deprecated_function(), ->suppress_errors(), ->get_results(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), get_network(), get_home_url(), parse_url(), update_option(), update_option(), get_site_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
!->get_results() && !is_subdomain_install() && !get_site_option()124_deprecated_function(), ->suppress_errors(), ->get_results(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), get_network(), get_home_url(), parse_url(), update_option(), update_option(), get_site_option(), get_network(), get_blog_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
!->get_results() && !is_subdomain_install() && get_site_option()127_deprecated_function(), ->suppress_errors(), ->get_results(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), get_network(), get_home_url(), parse_url(), set_url_scheme(), update_option(), update_option(), get_site_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
!->get_results() && !is_subdomain_install() && get_site_option()127_deprecated_function(), ->suppress_errors(), ->get_results(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), set_url_scheme(), get_network(), get_home_url(), parse_url(), update_option(), update_option(), get_site_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
!->get_results() && !is_subdomain_install() && !get_site_option()129_deprecated_function(), ->suppress_errors(), ->get_results(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), get_network(), get_home_url(), parse_url(), set_url_scheme(), update_option(), update_option(), get_site_option(), get_network(), get_blog_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
!->get_results() && !is_subdomain_install() && !get_site_option()129_deprecated_function(), ->suppress_errors(), ->get_results(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), set_url_scheme(), get_network(), get_home_url(), parse_url(), update_option(), update_option(), get_site_option(), get_network(), get_blog_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
!->get_results() && !is_subdomain_install() && get_site_option()132_deprecated_function(), ->suppress_errors(), ->get_results(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), set_url_scheme(), get_network(), get_home_url(), parse_url(), set_url_scheme(), update_option(), update_option(), get_site_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
!->get_results() && !is_subdomain_install() && !get_site_option()134_deprecated_function(), ->suppress_errors(), ->get_results(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), set_url_scheme(), get_network(), get_home_url(), parse_url(), set_url_scheme(), update_option(), update_option(), get_site_option(), get_network(), get_blog_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
8 further outcomes, up to 147 instructions
->get_results() && !is_subdomain_install() && get_site_option()135_deprecated_function(), ->suppress_errors(), ->get_results(), __(), __(), exit(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), get_network(), get_home_url(), parse_url(), update_option(), update_option(), get_site_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
->get_results() && !is_subdomain_install() && !get_site_option()137_deprecated_function(), ->suppress_errors(), ->get_results(), __(), __(), exit(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), get_network(), get_home_url(), parse_url(), update_option(), update_option(), get_site_option(), get_network(), get_blog_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
->get_results() && !is_subdomain_install() && get_site_option()140_deprecated_function(), ->suppress_errors(), ->get_results(), __(), __(), exit(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), get_network(), get_home_url(), parse_url(), set_url_scheme(), update_option(), update_option(), get_site_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
->get_results() && !is_subdomain_install() && get_site_option()140_deprecated_function(), ->suppress_errors(), ->get_results(), __(), __(), exit(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), set_url_scheme(), get_network(), get_home_url(), parse_url(), update_option(), update_option(), get_site_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
->get_results() && !is_subdomain_install() && !get_site_option()142_deprecated_function(), ->suppress_errors(), ->get_results(), __(), __(), exit(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), get_network(), get_home_url(), parse_url(), set_url_scheme(), update_option(), update_option(), get_site_option(), get_network(), get_blog_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
->get_results() && !is_subdomain_install() && !get_site_option()142_deprecated_function(), ->suppress_errors(), ->get_results(), __(), __(), exit(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), set_url_scheme(), get_network(), get_home_url(), parse_url(), update_option(), update_option(), get_site_option(), get_network(), get_blog_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
->get_results() && !is_subdomain_install() && get_site_option()145_deprecated_function(), ->suppress_errors(), ->get_results(), __(), __(), exit(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), set_url_scheme(), get_network(), get_home_url(), parse_url(), set_url_scheme(), update_option(), update_option(), get_site_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()
->get_results() && !is_subdomain_install() && !get_site_option()147_deprecated_function(), ->suppress_errors(), ->get_results(), __(), __(), exit(), ->suppress_errors(), get_blogaddress_by_id(), make_db_current_silent(), populate_options(), populate_roles(), untrailingslashit(), is_subdomain_install(), get_site_option(), parse_url(), set_url_scheme(), get_network(), get_home_url(), parse_url(), set_url_scheme(), update_option(), update_option(), get_site_option(), get_network(), get_blog_option(), update_option(), wp_unslash(), update_option(), update_option(), ->get_blog_prefix(), delete_metadata(), delete_metadata()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev157100–1475
8.5157100–1475
8.4157100–14752 more instructions than PHP 8.3
8.315533–1345
8.215533–1345
8.115533–13452 fewer instructions than PHP 7.4
7.415733–1365

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 · 17

Show all 17

Used by · 1

Source code

function install_blog( $blog_id, $blog_title = '' ) {	global $wpdb, $wp_roles; 	_deprecated_function( __FUNCTION__, '5.1.0' ); 	// Cast for security.	$blog_id = (int) $blog_id; 	require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 	$suppress = $wpdb->suppress_errors();	if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) {		die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p></body></html>' );	}	$wpdb->suppress_errors( $suppress ); 	$url = get_blogaddress_by_id( $blog_id ); 	// Set everything up.	make_db_current_silent( 'blog' );	populate_options();	populate_roles(); 	// populate_roles() clears previous role definitions so we start over.	$wp_roles = new WP_Roles(); 	$siteurl = $home = untrailingslashit( $url ); 	if ( ! is_subdomain_install() ) { 		if ( 'https' === parse_url( get_site_option( 'siteurl' ), PHP_URL_SCHEME ) ) {			$siteurl = set_url_scheme( $siteurl, 'https' );		}		if ( 'https' === parse_url( get_home_url( get_network()->site_id ), PHP_URL_SCHEME ) ) {			$home = set_url_scheme( $home, 'https' );		}	} 	update_option( 'siteurl', $siteurl );	update_option( 'home', $home ); 	if ( get_site_option( 'ms_files_rewriting' ) ) {		update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" );	} else {		update_option( 'upload_path', get_blog_option( get_network()->site_id, 'upload_path' ) );	} 	update_option( 'blogname', wp_unslash( $blog_title ) );	update_option( 'admin_email', '' ); 	// Remove all permissions.	$table_prefix = $wpdb->get_blog_prefix();	delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true );   // Delete all.	delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // Delete all.}

Changelog

Introduced in MU (3.0.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.

5.1.0
Deprecated.from the docblock
MU (3.0.0)
MU (3.0.0)from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/ms-deprecated.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.