create_empty_blog

函数
create_empty_blog ( $domain, $path, $weblog_title, $site_id = 1 )
参数
  • (string) $domain The new blog's domain.
    Required:
  • (string) $path The new blog's path.
    Required:
  • (string) $weblog_title The new blog's title.
    Required:
  • (int) $site_id Optional. Defaults to 1.
    Required:
    Default: 1
返回值
  • (string|int) The ID of the newly created blog
定义位置
相关方法
wpmu_create_blogrestore_current_blogwp_create_tagremove_user_from_blog__return_empty_string
引入
-
弃用
4.4.0

WordPress中的create_empty_blog函数是一个实用函数,它在WordPress的多站点网络中创建一个新的空博客。它接受两个参数,站点的URL和站点的标题,并返回新创建站点的站点ID。

创建一个空的博客。

function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) {
	_deprecated_function( __FUNCTION__, '4.4.0' );

	if ( empty($path) )
		$path = '/';

	// Check if the domain has been used already. We should return an error message.
	if ( domain_exists($domain, $path, $site_id) )
		return __( '<strong>Error:</strong> Site URL you’ve entered is already taken.' );

	/*
	 * Need to back up wpdb table names, and create a new wp_blogs entry for new blog.
	 * Need to get blog_id from wp_blogs, and create new table names.
	 * Must restore table names at the end of function.
	 */

	if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
		return __( '<strong>Error:</strong> There was a problem creating site entry.' );

	switch_to_blog($blog_id);
	install_blog($blog_id);
	restore_current_blog();

	return $blog_id;
}

常见问题

FAQs
查看更多 >