返回介绍

install_blog()

发布于 2017-09-11 01:03:53 字数 4629 浏览 1447 评论 0 收藏 0

install_blog( int $blog_id,  string $blog_title = '' )

Install an empty blog.


description

Creates the new blog tables and options. If calling this function directly, be sure to use switch_to_blog() first, so that $wpdb points to the new blog.


参数

$blog_id

(int) (Required) The value returned by insert_blog().

$blog_title

(string) (Optional) The title of the new site.

Default value: ''


源代码

File: wp-includes/ms-functions.php

function install_blog( $blog_id, $blog_title = '' ) {
	global $wpdb, $wp_roles;

	// Cast for security
	$blog_id = (int) $blog_id;

	require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );

	$suppress = $wpdb->suppress_errors();
	if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) )
		die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p></body></html>' );
	$wpdb->suppress_errors( $suppress );

	$url = get_blogaddress_by_id( $blog_id );

	// Set everything up
	make_db_current_silent( 'blog' );
	populate_options();
	populate_roles();

	// populate_roles() clears previous role definitions so we start over.
	$wp_roles = new WP_Roles();

	$siteurl = $home = untrailingslashit( $url );

	if ( ! is_subdomain_install() ) {

 		if ( 'https' === parse_url( get_site_option( 'siteurl' ), PHP_URL_SCHEME ) ) {
 			$siteurl = set_url_scheme( $siteurl, 'https' );
 		}
 		if ( 'https' === parse_url( get_home_url( get_network()->site_id ), PHP_URL_SCHEME ) ) {
 			$home = set_url_scheme( $home, 'https' );
 		}

	}

	update_option( 'siteurl', $siteurl );
	update_option( 'home', $home );

	if ( get_site_option( 'ms_files_rewriting' ) )
		update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" );
	else
		update_option( 'upload_path', get_blog_option( get_network()->site_id, 'upload_path' ) );

	update_option( 'blogname', wp_unslash( $blog_title ) );
	update_option( 'admin_email', '' );

	// remove all perms
	$table_prefix = $wpdb->get_blog_prefix();
	delete_metadata( 'user', 0, $table_prefix . 'user_level',   null, true ); // delete all
	delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // delete all
}

更新日志

Versiondescription
MUIntroduced.

相关函数

Uses

  • wp-includes/ms-blogs.php: get_network()
  • wp-admin/includes/schema.php: populate_roles()
  • wp-admin/includes/schema.php: populate_options()
  • wp-admin/includes/upgrade.php: make_db_current_silent()
  • wp-includes/class-wp-roles.php: WP_Roles::__construct()
  • wp-includes/l10n.php: __()
  • wp-includes/formatting.php: wp_unslash()
  • wp-includes/formatting.php: untrailingslashit()
  • wp-includes/link-template.php: set_url_scheme()
  • wp-includes/link-template.php: get_home_url()
  • wp-includes/option.php: get_site_option()
  • wp-includes/option.php: update_option()
  • wp-includes/ms-load.php: is_subdomain_install()
  • wp-includes/ms-blogs.php: get_blog_option()
  • wp-includes/ms-blogs.php: get_blogaddress_by_id()
  • wp-includes/wp-db.php: wpdb::get_results()
  • wp-includes/wp-db.php: wpdb::suppress_errors()
  • wp-includes/wp-db.php: wpdb::get_blog_prefix()
  • wp-includes/meta.php: delete_metadata()
  • Show 14 more uses Hide more uses

Used By

  • wp-includes/ms-functions.php: wpmu_create_blog()
  • wp-includes/ms-deprecated.php: create_empty_blog()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Drew Jaynes

    Hi. I’d suggest checking out this ticket for progress on this issue: https://core.trac.wordpress.org/ticket/27499

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文