install_blog

Install an empty blog.

Description

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

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 (2)

0. $blog_id (int)
The value returned by insert_blog().
1. $blog_title — Optional. (string) => ''
The title of the new site.

Usage

  1. if ( !function_exists( 'install_blog' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-functions.php'; 
  3.  
  4. // The value returned by insert_blog(). 
  5. $blog_id = -1; 
  6.  
  7. // The title of the new site. 
  8. $blog_title = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = install_blog($blog_id, $blog_title); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/ms-functions.php  
  1. function install_blog( $blog_id, $blog_title = '' ) { 
  2. global $wpdb, $wp_roles; 
  3.  
  4. // Cast for security 
  5. $blog_id = (int) $blog_id; 
  6.  
  7. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 
  8.  
  9. $suppress = $wpdb->suppress_errors(); 
  10. if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) 
  11. 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>' ); 
  12. $wpdb->suppress_errors( $suppress ); 
  13.  
  14. $url = get_blogaddress_by_id( $blog_id ); 
  15.  
  16. // Set everything up 
  17.  
  18. // populate_roles() clears previous role definitions so we start over. 
  19. $wp_roles = new WP_Roles(); 
  20.  
  21. $siteurl = $home = untrailingslashit( $url ); 
  22.  
  23. if ( ! is_subdomain_install() ) { 
  24.  
  25. if ( 'https' === parse_url( get_site_option( 'siteurl' ), PHP_URL_SCHEME ) ) { 
  26. $siteurl = set_url_scheme( $siteurl, 'https' ); 
  27. if ( 'https' === parse_url( get_home_url( get_network()->site_id ), PHP_URL_SCHEME ) ) { 
  28. $home = set_url_scheme( $home, 'https' ); 
  29.  
  30.  
  31. update_option( 'siteurl', $siteurl ); 
  32. update_option( 'home', $home ); 
  33.  
  34. if ( get_site_option( 'ms_files_rewriting' ) ) 
  35. update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" ); 
  36. else 
  37. update_option( 'upload_path', get_blog_option( get_network()->site_id, 'upload_path' ) ); 
  38.  
  39. update_option( 'blogname', wp_unslash( $blog_title ) ); 
  40. update_option( 'admin_email', '' ); 
  41.  
  42. // remove all perms 
  43. $table_prefix = $wpdb->get_blog_prefix(); 
  44. delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true ); // delete all 
  45. delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // delete all