insert_blog

Store basic site info in the blogs table.

Description

(int|false) insert_blog( (string) $domain, (string) $path, (int) $site_id ); 

This function creates a row in the wp_blogs table and returns the new blog's ID. It is the first step in creating a new blog.

Returns (int|false)

The ID of the new row

Parameters (3)

0. $domain (string)
The domain of the new site.
1. $path (string)
The path of the new site.
2. $site_id (int)
Unless you're running a multi-network install, be sure to set this value to 1.

Usage

  1. if ( !function_exists( 'insert_blog' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-functions.php'; 
  3.  
  4. // The domain of the new site. 
  5. $domain = ''; 
  6.  
  7. // The path of the new site. 
  8. $path = ''; 
  9.  
  10. // Unless you're running a multi-network install, be sure to set this value to 1. 
  11. $site_id = -1; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = insert_blog($domain, $path, $site_id); 
  15.  

Defined (1)

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

/wp-includes/ms-functions.php  
  1. function insert_blog($domain, $path, $site_id) { 
  2. global $wpdb; 
  3.  
  4. $path = trailingslashit($path); 
  5. $site_id = (int) $site_id; 
  6.  
  7. $result = $wpdb->insert( $wpdb->blogs, array('site_id' => $site_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql')) ); 
  8. if ( ! $result ) 
  9. return false; 
  10.  
  11. $blog_id = $wpdb->insert_id; 
  12. refresh_blog_details( $blog_id ); 
  13.  
  14.  
  15. return $blog_id;