install_blog( int $blog_id, string $blog_title = '' )
- Since
- MU (3.0.0)
- Source
wp-includes/ms-deprecated.php:610
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
- Scaling
- Constant
- Instructions
- 100–147
- Plugin surface
- None
- Called by
- 1
Reaches the database via ->get_results().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 157.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionnetwork option
get_site_option()called directly - sqldatabase query
->get_results()called directly - hookthird-party callbacks
do_action()one call below install_blog() - serializeserialisation
maybe_serialize()one call below install_blog() - cacheobject cache
wp_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.
| When | Instructions | Calls 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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 157 | 100–147 | 5 | |
| 8.5 | 157 | 100–147 | 5 | |
| 8.4 | 157 | 100–147 | 5 | 2 more instructions than PHP 8.3 |
| 8.3 | 155 | 33–134 | 5 | |
| 8.2 | 155 | 33–134 | 5 | |
| 8.1 | 155 | 33–134 | 5 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 157 | 33–136 | 5 |
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
- _deprecated_function()Marks a function as deprecated and inform when it has been used.
- __()Retrieves the translation of $text.
- get_blogaddress_by_id()Gets a full site URL, given a site ID.
- make_db_current_silent()Updates the database tables to a new schema, but without displaying results.
- populate_options()Create WordPress options and set the default values.
- populate_roles()Execute WordPress role creation for the various WordPress versions.
- untrailingslashit()Removes trailing forward slashes and backslashes if they exist.
- is_subdomain_install()Whether a subdomain configuration is enabled.
- get_site_option()Retrieve an option value for the current network based on name of option.
- set_url_scheme()Sets the scheme for a URL.
- get_home_url()Retrieves the URL for a given site where the front end is accessible.
- get_network()Retrieves network data given a network ID or network object.
Show all 17
- update_option()Updates the value of an option that was already added.
- get_blog_option()Retrieves option value for a given blog id based on name of option.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- delete_metadata()Deletes metadata for the specified object.
- WP_Roles::__construct()Constructor.
Used by · 1
- create_empty_blog()Create an empty blog.
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.
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/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.