wpmu_create_blog()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wpmu_create_blog( string $domain, string $path, string $title, int $user_id, array $options = array(), int $network_id = 1 ): int|WP_Error
Описание
Эта функция выполняется как при самостоятельной регистрации нового сайта пользователем, так и при создании нового сайта суперадминистратором. Подключайтесь к 'wpmu_new_blog' для событий, которые должны затрагивать все новые сайты.
В установках с подкаталогами $domain совпадает с доменом основного сайта, а путь — это имя подкаталога (например, 'example.com' и '/blog1/'). В установках с поддоменами $domain — это новый поддомен плюс корневой домен (например, 'blog1.example.com'), а $path — '/'.
Оригинал (английский)
This function runs when a user self-registers a new site as well as when a Super Admin creates a new site. Hook to ‘wpmu_new_blog’ for events that should affect all new sites.
On subdirectory installations, $domain is the same as the main site’s domain, and the path is the subdirectory name (eg ‘example.com’ and ‘/blog1/’). On subdomain installations, $domain is the new subdomain + root domain (eg ‘blog1.example.com’), and $path is ‘/’.
Параметры
$domain
string
обязательный
$path
string
обязательный
$title
string
обязательный
$user_id
int
обязательный
$options
array
необязательный
= array()
$network_id
int
необязательный
= 1
Возвращаемое значение
int|WP_Error
Исходный код
wp-includes/ms-functions.php:1404
function wpmu_create_blog( $domain, $path, $title, $user_id, $options = array(), $network_id = 1 ) {
$defaults = array(
'public' => 0,
);
$options = wp_parse_args( $options, $defaults );
$title = strip_tags( $title );
$user_id = (int) $user_id;
// Check if the domain has been used already. We should return an error message.
if ( domain_exists( $domain, $path, $network_id ) ) {
return new WP_Error( 'blog_taken', __( 'Sorry, that site already exists!' ) );
}
if ( ! wp_installing() ) {
wp_installing( true );
}
$allowed_data_fields = array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' );
$site_data = array_merge(
array(
'domain' => $domain,
'path' => $path,
'network_id' => $network_id,
),
array_intersect_key( $options, array_flip( $allowed_data_fields ) )
);
// Data to pass to wp_initialize_site().
$site_initialization_data = array(
'title' => $title,
'user_id' => $user_id,
'options' => array_diff_key( $options, array_flip( $allowed_data_fields ) ),
);
$blog_id = wp_insert_site( array_merge( $site_data, $site_initialization_data ) );
if ( is_wp_error( $blog_id ) ) {
return $blog_id;
}
wp_cache_set_sites_last_changed();
return $blog_id;
}
История изменений
| Версия | Описание |
|---|---|
| MU (3.0.0) | Introduced. |

