multisite – Programmatically creating site in a network



Create multiple, predefined sites using wordpress multisite on plugin activation.

Current Code

    $domains = array('however', 'many', 'hardcoded', 'subdomains',);

    foreach($domains as $domain){
        $meta = array(
            'public' => 1,
            'WPLANG' => '',
        $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', get_network()->domain );
        $user_id  = get_option('admin_email');
        $id = wpmu_create_blog( $newdomain, get_network()->path, $domain, $user_id, $meta, get_current_network_id() );
        if ( ! is_wp_error( $id ) ) {
            update_user_option( $user_id, $domain, $id, true );

Current Functionality

The code creates the sites and they are listed on the sites page in the network admin panel.

Current Issues

Sites created with this code don’t have a user set as admin. The sites are also not listed in the ‘my sites’ drop down., but I’m willing to bet that it’s because there’s no admin set on the sites.

Where I need help

I’ve sifted through the files in the wp-admin/network and can’t figure out what function I’m needing to incorporate that sets a user as an admin of a subnetwork site. What function would I need to finish off the plugin activation code?

Ryan Cochran 9 months 2022-04-29T20:41:20-05:00 0 Answers 0 views 0

Leave an answer