wpmu_create_blog
函数
wpmu_create_blog ( $domain, $path, $title, $user_id, $options = array(), $network_id = 1 )
- 参数
-
-
(string)
$domain
The new site’s domain.- Required: 是
-
(string)
$path
The new site’s path.- Required: 是
-
(string)
$title
The new site’s title.- Required: 是
-
(int)
$user_id
The user ID of the new site’s admin.- Required: 是
-
(array)
$options
Optional. Array of key=>value pairs used to set initial site options. If valid status keys are included (‘public’, ‘archived’, ‘mature’, ‘spam’, ‘deleted’, or ‘lang_id’) the given site status(es) will be updated. Otherwise, keys and values will be used to set options for the new site. Default empty array.- Required: 否
- Default: array()
-
(int)
$network_id
Optional. Network ID. Only relevant on multi-network installations.- Required: 否
- Default: 1
-
(string)
- 返回值
-
- (int|WP_Error) Returns WP_Error object on failure, the new site ID on success.
- 定义位置
-
-
wp-includes/ms-functions.php
, line 1357
-
wp-includes/ms-functions.php
- 引入
- –
- 弃用
- –
Creates a site.
This function runs when a user self-registers a new site as well
as when a Super Admin creates a new site. Hook to {@see ‘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 ‘/’.
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( 'last_changed', microtime(), 'sites' );
return $blog_id;
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。