wp_install

Installs the site.

Description

(array) wp_install( (string) $blog_title, (string) $user_name, (string) $user_email, (bool) $public, (string) $deprecated = '', (string) $user_password = '', (string) $language = '' ); 

Runs the required functions to set up and populate the database, including primary admin user and initial options.

Returns (array)

Array keys 'url', 'user_id', 'password', and 'password_message'.

Parameters (7)

0. $blog_title (string)
The blog title.
1. $user_name (string)
User's username.
2. $user_email (string)
The user email.
3. $public (bool)
Whether site is public.
4. $deprecated — Optional. (string) => ''
Not used.
5. $user_password — Optional. (string) => ''
User's chosen password. Default empty (random password).
6. $language — Optional. (string) => ''
Language chosen. Default empty.

Usage

  1. if ( !function_exists( 'wp_install' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/upgrade.php'; 
  3.  
  4. // The blog title. 
  5. $blog_title = ''; 
  6.  
  7. // User's username. 
  8. $user_name = ''; 
  9.  
  10. // The user email. 
  11. $user_email = ''; 
  12.  
  13. // Whether site is public. 
  14. $public = true; 
  15.  
  16. // Optional. Not used. 
  17. $deprecated = ''; 
  18.  
  19. // Optional. User's chosen password. Default empty (random password). 
  20. $user_password = ''; 
  21.  
  22. // Optional. Language chosen. Default empty. 
  23. $language = ''; 
  24.  
  25. // NOTICE! Understand what this does before running. 
  26. $result = wp_install($blog_title, $user_name, $user_email, $public, $deprecated, $user_password, $language); 
  27.  

Defined (1)

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

/wp-admin/includes/upgrade.php  
  1. function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) { 
  2. if ( !empty( $deprecated ) ) 
  3. _deprecated_argument( __FUNCTION__, '2.6.0' ); 
  4.  
  5.  
  6. update_option('blogname', $blog_title); 
  7. update_option('admin_email', $user_email); 
  8. update_option('blog_public', $public); 
  9.  
  10. // Freshness of site - in the future, this could get more specific about actions taken, perhaps. 
  11. update_option( 'fresh_site', 1 ); 
  12.  
  13. if ( $language ) { 
  14. update_option( 'WPLANG', $language ); 
  15.  
  16. $guessurl = wp_guess_url(); 
  17.  
  18. update_option('siteurl', $guessurl); 
  19.  
  20. // If not a public blog, don't ping. 
  21. if ( ! $public ) 
  22. update_option('default_pingback_flag', 0); 
  23.  
  24. /** 
  25. * Create default user. If the user already exists, the user tables are 
  26. * being shared among sites. Just set the role in that case. 
  27. */ 
  28. $user_id = username_exists($user_name); 
  29. $user_password = trim($user_password); 
  30. $email_password = false; 
  31. if ( !$user_id && empty($user_password) ) { 
  32. $user_password = wp_generate_password( 12, false ); 
  33. $message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.'); 
  34. $user_id = wp_create_user($user_name, $user_password, $user_email); 
  35. update_user_option($user_id, 'default_password_nag', true, true); 
  36. $email_password = true; 
  37. } elseif ( ! $user_id ) { 
  38. // Password has been provided 
  39. $message = '<em>'.__('Your chosen password.').'</em>'; 
  40. $user_id = wp_create_user($user_name, $user_password, $user_email); 
  41. } else { 
  42. $message = __('User already exists. Password inherited.'); 
  43.  
  44. $user = new WP_User($user_id); 
  45. $user->set_role('administrator'); 
  46.  
  47. wp_install_defaults($user_id); 
  48.  
  49.  
  50.  
  51. wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during the install.') ) ); 
  52.  
  53.  
  54. /** 
  55. * Fires after a site is fully installed. 
  56. * @since 3.9.0 
  57. * @param WP_User $user The site owner. 
  58. */ 
  59. do_action( 'wp_install', $user ); 
  60.  
  61. return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);