^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数install_blog()用法示例

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

Install an empty blog.


描述

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.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包


参数

$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
}

更新日志

Version 描述
MU Introduced.

相关函数

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


Used By

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

  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

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈