On this page
install_blog( int $blog_id, string $blog_title = '' )
This function has been deprecated.
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.
Parameters
$blog_idint Required-
The value returned by wp_insert_site() .
$blog_titlestring Optional-
The title of the new site.
Default:
''
Source
File: wp-includes/ms-deprecated.php. View all references
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.
}
Related
Uses
| Uses | Description |
|---|---|
| get_network() wp-includes/ms-network.php | Retrieves network data given a network ID or network object. |
| set_url_scheme() wp-includes/link-template.php | Sets the scheme for a URL. |
| wpdb::get_blog_prefix() wp-includes/class-wpdb.php | Gets blog prefix. |
| wpdb::suppress_errors() wp-includes/class-wpdb.php | Enables or disables suppressing of database errors. |
| get_blogaddress_by_id() wp-includes/ms-blogs.php | Get a full blog URL, given a blog ID. |
| get_blog_option() wp-includes/ms-blogs.php | Retrieve option value for a given blog id based on name of option. |
| is_subdomain_install() wp-includes/ms-load.php | Whether a subdomain configuration is enabled. |
| populate_roles() wp-admin/includes/schema.php | Execute WordPress role creation for the various WordPress versions. |
| get_home_url() wp-includes/link-template.php | Retrieves the URL for a given site where the front end is accessible. |
| WP_Roles::__construct() wp-includes/class-wp-roles.php | Constructor. |
| untrailingslashit() wp-includes/formatting.php | Removes trailing forward slashes and backslashes if they exist. |
| make_db_current_silent() wp-admin/includes/upgrade.php | Updates the database tables to a new schema, but without displaying results. |
| populate_options() wp-admin/includes/schema.php | Create WordPress options and set the default values. |
| delete_metadata() wp-includes/meta.php | Deletes metadata for the specified object. |
| _deprecated_function() wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. |
| get_site_option() wp-includes/option.php | Retrieve an option value for the current network based on name of option. |
| update_option() wp-includes/option.php | Updates the value of an option that was already added. |
| wp_unslash() wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| wpdb::get_results() wp-includes/class-wpdb.php | Retrieves an entire SQL result set from the database (i.e., many rows). |
Used By
| Used By | Description |
|---|---|
| create_empty_blog() wp-includes/ms-deprecated.php | Create an empty blog. |
Changelog
| Version | Description |
|---|---|
| 5.1.0 | This function has been deprecated. |
| MU (3.0.0) | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/install_blog