function install_blog($blog_id, $blog_title = '') {}

Install an empty blog.
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.


  • int $blog_id: The value returned by insert_blog().
  • string $blog_title: The title of the new site.

Source code

function install_blog($blog_id, $blog_title = '') {

	global $wpdb, $table_prefix, $wp_roles;


	// Cast for security

	$blog_id = (int) $blog_id;

	require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );

	if ( $wpdb->get_results("SELECT ID FROM $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>');


	$url = get_blogaddress_by_id($blog_id);

	// Set everything up

	make_db_current_silent( 'blog' );




	// fix url.

	update_option('siteurl', $url);

	update_option('home', $url);

	update_option('fileupload_url', $url . "files" );

	update_option('upload_path', UPLOADBLOGSDIR . "/$blog_id/files");

	update_option('blogname', stripslashes( $blog_title ) );

	update_option('admin_email', '');

	$wpdb->update( $wpdb->options, array('option_value' => ''), array('option_name' => 'admin_email') );

	// remove all perms

	$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE meta_key = %s", $table_prefix.'user_level') );

	$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE meta_key = %s", $table_prefix.'capabilities') );

	$wpdb->suppress_errors( false );



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: