Creating multisite in wordpress using php

I am trying to create multisite in wordpress, I am using WPMU DEV and adding new sites through My Sites -> Network Admin -> Sites -> Add New, is there any way I could write a php code to automate this part and add site dynamicall instead of adding them dynamically. I hope my question is not too confusing, I would appreciate any help.

Thanks

Solutions Collecting From Web of "Creating multisite in wordpress using php"

There is a PHP function to create sites: wpmu_create_blog(). The simplest example is:

<?php 
$domain = "something.example.com";
$path = "/";
$title = "Look at my awesome site";
wpmu_create_blog($domain, $path, $title);

The catch here is you need to have WordPress loaded too in your PHP. If you are doing this as part of a plugin, then you’ll have no problem. But if you are doing this from an outside script, then you’ll need to manually load WordPress PHP code.

<?php
# Load WordPress barebones
define( 'WP_USE_THEMES', false );
require( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );

$domain = "something.example.com";
$path = "/";
$title = "Look at my awesome site";
wpmu_create_blog($domain, $path, $title);

I’ve omitted an security checking here which I leave to you.