create_empty_blog

Create an empty blog.

Description

(string|int) create_empty_blog( (string) $domain, (string) $path, (string) $weblog_title, (int) $site_id = 1 ); 

Returns (string|int)

The ID of the newly created blog

Parameters (4)

0. $domain (string)
The new blog's domain.
1. $path (string)
The new blog's path.
2. $weblog_title (string)
The new blog's title.
3. $site_id — Optional. (int) => 1
Defaults to 1.

Usage

  1. if ( !function_exists( 'create_empty_blog' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-deprecated.php'; 
  3.  
  4. // The new blog's domain. 
  5. $domain = ''; 
  6.  
  7. // The new blog's path. 
  8. $path = ''; 
  9.  
  10. // The new blog's title. 
  11. $weblog_title = ''; 
  12.  
  13. // Optional. Defaults to 1. 
  14. $site_id = 1; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = create_empty_blog($domain, $path, $weblog_title, $site_id); 
  18.  

Defined (1)

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

/wp-includes/ms-deprecated.php  
  1. function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) { 
  2. _deprecated_function( __FUNCTION__, '4.4.0' ); 
  3.  
  4. if ( empty($path) ) 
  5. $path = '/'; 
  6.  
  7. // Check if the domain has been used already. We should return anerrormessage. 
  8. if ( domain_exists($domain, $path, $site_id) ) 
  9. return __( '<strong>ERROR</strong>: Site URL already taken.' ); 
  10.  
  11. // Need to back up wpdb table names, and create a new wp_blogs entry for new blog. 
  12. // Need to get blog_id from wp_blogs, and create new table names. 
  13. // Must restore table names at the end of function. 
  14.  
  15. if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) 
  16. return __( '<strong>ERROR</strong>: problem creating site entry.' ); 
  17.  
  18. switch_to_blog($blog_id); 
  19. install_blog($blog_id); 
  20.  
  21. return $blog_id;