Advertisements

wpmu_create_blog

Definition:
function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1) {}

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.

Parameters

  • string $domain: The new site’s domain.
  • string $path: The new site’s path.
  • string $title: The new site’s title.
  • int $user_id: The user ID of the new site’s admin.
  • array $meta: Optional. Used to set initial site options.
  • int $site_id: Optional. Only relevant on multi-network installs.

Return values

returns:Returns WP_Error object on failure, int $blog_id on success

Defined actions

  • wpmu_new_blog
    do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta );

Source code

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', __('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;

}

3377

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: