wpmu_create_blog [ WordPress Functions ]
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
| Codex |
Create a site.
This function runs when a user self-registers a new site as well as when a Super Admin creates a new site. Hook to 'wpmu_new_blog' for events that should affect all new sites.
On subdirectory installs, $domain is the same as the main site's domain, and the path is the subdirectory name (eg 'example.com' and '/blog1/'). On subdomain installs, $domain is the new subdomain + root domain (eg 'blog1.example.com'), and $path is '/'.
Source
function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1) {
$domain = preg_replace( '/\s+/', '', sanitize_user( $domain, true ) );
if ( is_subdomain_install() )
$domain = str_replace( '@', '', $domain );
$title = strip_tags( $title );
$user_id = (int) $user_id;
if ( empty($path) )
$path = '/';
// Check if the domain has been used already. We should return an error message.
if ( domain_exists($domain, $path, $site_id) )
return new WP_Error( 'blog_taken', __( 'Sorry, that site already exists!' ) );
if ( !defined('WP_INSTALLING') )
define( 'WP_INSTALLING', true );
if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
return new WP_Error('insert_blog', __('Could not create site.'));
switch_to_blog($blog_id);
install_blog($blog_id, $title);
wp_install_defaults($user_id);
add_user_to_blog($blog_id, $user_id, 'administrator');
if ( is_array($meta) ) foreach ($meta as $key => $value) {
if ( $key == 'public' || $key == 'archived' || $key == 'mature' || $key == 'spam' || $key == 'deleted' || $key == 'lang_id' )
update_blog_status( $blog_id, $key, $value );
else
update_option( $key, $value );
}
add_option( 'WPLANG', get_site_option( 'WPLANG' ) );
update_option( 'blog_public', (int)$meta['public'] );
if ( ! is_super_admin( $user_id ) && ! get_user_meta( $user_id, 'primary_blog', true ) )
update_user_meta( $user_id, 'primary_blog', $blog_id );
restore_current_blog();
do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta );
return $blog_id;
}Examples [ wp-snippets.com ]
Top Google Search Results
- WPMU Functions/wpmu create blog « WordPress Codex
Description. Creates a new blog (site). This function runs when a user self- registers a new site as well as when a Super Admin creates a new site. Hook to ...
codex.wordpress.org - wpmu_create_blog (WordPress Function) - WPSeek.com
Jun 9, 2013 ... Create a site. WordPress lookup for wpmu_create_blog, a WordPress Function.
wpseek.com - php - Wordpress Multi Site (Networking enabled) - Stack Overflow
global $current_site; wpmu_create_blog( $current_site->domain, ... wpmu_create_blog adds all the information to the database ( I can query ...
stackoverflow.com - WordPress network: set themes and plugins for new blog ...
May 14, 2012 ... How can I enable specific themes and plugins for new blogs that have been created with wpmu_create_blog ? I'd like to set the themes and ...
wordpress.stackexchange.com
User discussions [ wordpress.org ]
- eye8 on "Bug? Correct timezone is not applied to dummy post in multisite"
- David Sader on "Bug? Correct timezone is not applied to dummy post in multisite"
- eye8 on "Bug? Correct timezone is not applied to dummy post in multisite"
- David Sader on "Bug? Correct timezone is not applied to dummy post in multisite"
- David Sader on "Bug? Correct timezone is not applied to dummy post in multisite"
- David Sader on "Bug? Correct timezone is not applied to dummy post in multisite"
- eye8 on "Bug? Correct timezone is not applied to dummy post in multisite"
- Ipstenu (Mika E.) on "Bug? Correct timezone is not applied to dummy post in multisite"
- eye8 on "Bug? Correct timezone is not applied to dummy post in multisite"
- Ipstenu (Mika E.) on "Bug? Correct timezone is not applied to dummy post in multisite"
