Automatically create site in multisite WordPress installation

I have a multisite WordPress installation that I want to connect to a different application via webservices. I’m getting a list of users and I need to create sites automatically. I’m not sure how exactly to do that. Any tips would be appreciated. Thanks.

Related posts

Leave a Reply

1 comment

  1. This is handled internally by WordPress using a file called /wp-admin/network/site-new.php by calling the wpmu_create_blog() function.

    global $wpdb;
    
    $domain = 'example.com';          // your domain (or subdomain)
    $path = '/blog';                  // path to your site
    $title = 'My Site';               // site title
    $user_id = get_current_user_id(); // the user id that owns this site
    
    // hide db errors
    $wpdb->hide_errors();
    // create the new site
    $id = wpmu_create_blog( $domain, $path, $title, $user_id , array( 'public' => true ) );
    // enable db errors
    $wpdb->show_errors();