: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ( get_network( $network_id ) ) {
$errors->add( 'siteid_exists', __( 'The network already exists.' ) );
if ( $network_id === (int) $wpdb->get_var(
$wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id )
$errors->add( 'siteid_exists', __( 'The network already exists.' ) );
if ( ! is_email( $email ) ) {
$errors->add( 'invalid_email', __( 'You must provide a valid email address.' ) );
if ( $errors->has_errors() ) {
if ( 1 === $network_id ) {
$network_id = $wpdb->insert_id;
'site_name' => $site_name,
'subdomain_install' => $subdomain_install,
* When upgrading from single to multisite, assume the current site will
* become the main site of the network. When using populate_network()
* to create another network in an existing multisite environment, skip
* these steps since the main site of the new network has not yet been
if ( ! is_multisite() ) {
$current_site = new stdClass();
$current_site->domain = $domain;
$current_site->path = $path;
$current_site->site_name = ucfirst( $domain );
'site_id' => $network_id,
'registered' => current_time( 'mysql' ),
$current_site->blog_id = $wpdb->insert_id;
$site_user_id = (int) $wpdb->get_var(
WHERE meta_key = %s AND site_id = %d",
update_user_meta( $site_user_id, 'source_domain', $domain );
update_user_meta( $site_user_id, 'primary_blog', $current_site->blog_id );
// Unable to use update_network_option() while populating the network.
'site_id' => $network_id,
'meta_key' => 'main_site',
'meta_value' => $current_site->blog_id,
if ( $subdomain_install ) {
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
$wp_rewrite->set_permalink_structure( '/blog/%year%/%monthnum%/%day%/%postname%/' );
if ( ! $subdomain_install ) {
$hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname!
if ( is_wp_error( $page ) ) {
$errstr = $page->get_error_message();
} elseif ( 200 === wp_remote_retrieve_response_code( $page ) ) {
$msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>';
/* translators: %s: Host name. */
__( 'The installer attempted to contact a random hostname (%s) on your domain.' ),
'<code>' . $hostname . '</code>'
if ( ! empty( $errstr ) ) {
/* translators: %s: Error message. */
$msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), '<code>' . $errstr . '</code>' );
/* translators: %s: Asterisk symbol (*). */
__( 'To use a subdomain configuration, you must have a wildcard entry in your DNS. This usually means adding a %s hostname record pointing at your web server in your DNS configuration tool.' ),
$msg .= '<p>' . __( 'You can still use your site but any subdomain you create may not be accessible. If you know your DNS is correct, ignore this message.' ) . '</p>';
return new WP_Error( 'no_wildcard_dns', $msg );
* Creates WordPress network meta and sets the default values.
* @global wpdb $wpdb WordPress database abstraction object.
* @global int $wp_db_version WordPress database version.
* @param int $network_id Network ID to populate meta for.
* @param array $meta Optional. Custom meta $key => $value pairs to use. Default empty array.
function populate_network_meta( $network_id, array $meta = array() ) {
global $wpdb, $wp_db_version;
$network_id = (int) $network_id;
$email = ! empty( $meta['admin_email'] ) ? $meta['admin_email'] : '';
$subdomain_install = isset( $meta['subdomain_install'] ) ? (int) $meta['subdomain_install'] : 0;
// If a user with the provided email does not exist, default to the current user as the new network admin.
$site_user = ! empty( $email ) ? get_user_by( 'email', $email ) : false;
if ( false === $site_user ) {
$site_user = wp_get_current_user();
$email = $site_user->user_email;
$template = get_option( 'template' );
$stylesheet = get_option( 'stylesheet' );
$allowed_themes = array( $stylesheet => true );
if ( $template !== $stylesheet ) {
$allowed_themes[ $template ] = true;
if ( WP_DEFAULT_THEME !== $stylesheet && WP_DEFAULT_THEME !== $template ) {
$allowed_themes[ WP_DEFAULT_THEME ] = true;
// If WP_DEFAULT_THEME doesn't exist, also include the latest core default theme.
if ( ! wp_get_theme( WP_DEFAULT_THEME )->exists() ) {
$core_default = WP_Theme::get_core_default_theme();
$allowed_themes[ $core_default->get_stylesheet() ] = true;
if ( function_exists( 'clean_network_cache' ) ) {
clean_network_cache( $network_id );
wp_cache_delete( $network_id, 'networks' );
if ( ! is_multisite() ) {
$site_admins = array( $site_user->user_login );
'fields' => array( 'user_login' ),
'role' => 'administrator',
foreach ( $users as $user ) {
$site_admins[] = $user->user_login;
$site_admins = array_unique( $site_admins );
$site_admins = get_site_option( 'site_admins' );
/* translators: Do not translate USERNAME, SITE_NAME, BLOG_URL, PASSWORD: those are placeholders. */
Your new SITE_NAME site has been successfully set up at:
You can log in to the administrator account with the following information:
Log in here: BLOG_URLwp-login.php
We hope you enjoy your new site. Thanks!
$allowed_file_types = array();
$all_mime_types = get_allowed_mime_types();
foreach ( $all_mime_types as $ext => $mime ) {
array_push( $allowed_file_types, ...explode( '|', $ext ) );
$upload_filetypes = array_unique( $allowed_file_types );
'site_name' => __( 'My Network' ),
'admin_user_id' => $site_user->ID,
'registration' => 'none',
'upload_filetypes' => implode( ' ', $upload_filetypes ),
'blog_upload_space' => 100,
'fileupload_maxk' => 1500,
'site_admins' => $site_admins,
'allowedthemes' => $allowed_themes,
'illegal_names' => array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' ),
'wpmu_upgrade_site' => $wp_db_version,
'welcome_email' => $welcome_email,
/* translators: %s: Site link. */
'first_post' => __( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ),
// @todo - Network admins should have a method of editing the network siteurl (used for cookie hash).
'siteurl' => get_option( 'siteurl' ) . '/',
'upload_space_check_disabled' => is_multisite() ? get_site_option( 'upload_space_check_disabled' ) : '1',
'subdomain_install' => $subdomain_install,
'ms_files_rewriting' => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0',
'user_count' => get_site_option( 'user_count' ),
'initial_db_version' => get_option( 'initial_db_version' ),
'active_sitewide_plugins' => array(),
'WPLANG' => get_locale(),
if ( ! $subdomain_install ) {
$sitemeta['illegal_names'][] = 'blog';
$sitemeta = wp_parse_args( $meta, $sitemeta );
* Filters meta for a network on creation.
* @param array $sitemeta Associative array of network meta keys and values to be inserted.
* @param int $network_id ID of network to populate.
$sitemeta = apply_filters( 'populate_network_meta', $sitemeta, $network_id );
foreach ( $sitemeta as $meta_key => $meta_value ) {
if ( is_array( $meta_value ) ) {
$meta_value = serialize( $meta_value );
if ( ! empty( $insert ) ) {
$insert .= $wpdb->prepare( '( %d, %s, %s)', $network_id, $meta_key, $meta_value );
$wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
* Creates WordPress site meta and sets the default values.
* @global wpdb $wpdb WordPress database abstraction object.
* @param int $site_id Site ID to populate meta for.
* @param array $meta Optional. Custom meta $key => $value pairs to use. Default empty array.
function populate_site_meta( $site_id, array $meta = array() ) {
$site_id = (int) $site_id;
if ( ! is_site_meta_supported() ) {
* Filters meta for a site on creation.
* @param array $meta Associative array of site meta keys and values to be inserted.
* @param int $site_id ID of site to populate.
$site_meta = apply_filters( 'populate_site_meta', $meta, $site_id );
foreach ( $site_meta as $meta_key => $meta_value ) {
if ( is_array( $meta_value ) ) {
$meta_value = serialize( $meta_value );
if ( ! empty( $insert ) ) {
$insert .= $wpdb->prepare( '( %d, %s, %s)', $site_id, $meta_key, $meta_value );
$wpdb->query( "INSERT INTO $wpdb->blogmeta ( blog_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
wp_cache_delete( $site_id, 'blog_meta' );
wp_cache_set_sites_last_changed();