2

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

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.