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
返回值
  • (int|WP_Error) Returns WP_Error object on failure, the new site ID on success.
定義位置
相關方法
wpmu_delete_blogwp_create_tagwpmu_create_userwp_create_noncewp_create_thumbnail
引入
-
棄用
-

wpmu_create_blog – 這個函式在網路中建立一個新的站點,它接受的引數包括站點地址、站點標題、新站點管理員的使用者ID等等。

建立一個站點。

當使用者自行註冊一個新站點以及超級管理員建立一個新站點時,該函式會執行。鉤住{@see ‘wpmu_new_blog’}的事件,應該會影響到所有的新站點。

在子目錄安裝中,$domain與主站點的域名相同,而路徑是子目錄的名稱(例如’example.com’和’/blog1/’)。在子域安裝中,$domain是新的子域+根域(例如’blog1.example.com’),而$path是’/’。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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;
}

常見問題

FAQs
檢視更多 >