返回介绍

wp_install()

发布于 2017-09-11 12:15:24 字数 5388 浏览 1010 评论 0 收藏 0

wp_install( string $blog_title,  string $user_name,  string $user_email,  bool $public,  string $deprecated = '',  string $user_password = '',  string $language = '' )

Installs the site.


description

Runs the required functions to set up and populate the database, including primary admin user and initial options.


参数

$blog_title

(string) (Required) Site title.

$user_name

(string) (Required) User's username.

$user_email

(string) (Required) User's email.

$public

(bool) (Required) Whether site is public.

$deprecated

(string) (Optional) Not used.

Default value: ''

$user_password

(string) (Optional) User's chosen password. Default empty (random password).

Default value: ''

$language

(string) (Optional) Language chosen.

Default value: ''


返回值

(array) Array keys 'url', 'user_id', 'password', and 'password_message'.


源代码

File: wp-admin/includes/upgrade.php

function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) {
	if ( !empty( $deprecated ) )
		_deprecated_argument( __FUNCTION__, '2.6.0' );

	wp_check_mysql_version();
	wp_cache_flush();
	make_db_current_silent();
	populate_options();
	populate_roles();

	update_option('blogname', $blog_title);
	update_option('admin_email', $user_email);
	update_option('blog_public', $public);

	// Freshness of site - in the future, this could get more specific about actions taken, perhaps.
	update_option( 'fresh_site', 1 );

	if ( $language ) {
		update_option( 'WPLANG', $language );
	}

	$guessurl = wp_guess_url();

	update_option('siteurl', $guessurl);

	// If not a public blog, don't ping.
	if ( ! $public )
		update_option('default_pingback_flag', 0);

	/*
	 * Create default user. If the user already exists, the user tables are
	 * being shared among sites. Just set the role in that case.
	 */
	$user_id = username_exists($user_name);
	$user_password = trim($user_password);
	$email_password = false;
	if ( !$user_id && empty($user_password) ) {
		$user_password = wp_generate_password( 12, false );
		$message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.');
		$user_id = wp_create_user($user_name, $user_password, $user_email);
		update_user_option($user_id, 'default_password_nag', true, true);
		$email_password = true;
	} elseif ( ! $user_id ) {
		// Password has been provided
		$message = '<em>'.__('Your chosen password.').'</em>';
		$user_id = wp_create_user($user_name, $user_password, $user_email);
	} else {
		$message = __('User already exists. Password inherited.');
	}

	$user = new WP_User($user_id);
	$user->set_role('administrator');

	wp_install_defaults($user_id);

	wp_install_maybe_enable_pretty_permalinks();

	flush_rewrite_rules();

	wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during the install.') ) );

	wp_cache_flush();

	/**
	 * Fires after a site is fully installed.
	 *
	 * @since 3.9.0
	 *
	 * @param WP_User $user The site owner.
	 */
	do_action( 'wp_install', $user );

	return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
}

更新日志

Versiondescription
2.1.0Introduced.

相关函数

Uses

  • wp-admin/includes/upgrade.php: wp_install_maybe_enable_pretty_permalinks()
  • wp-admin/includes/schema.php: populate_roles()
  • wp-admin/includes/schema.php: populate_options()
  • wp-admin/includes/upgrade.php: wp_check_mysql_version()
  • wp-admin/includes/upgrade.php: make_db_current_silent()
  • wp-admin/includes/upgrade.php: wp_install_defaults()
  • wp-admin/includes/upgrade.php: wp_new_blog_notification()
  • wp-admin/includes/upgrade.php: wp_install
  • wp-includes/class-wp-user.php: WP_User::__construct()
  • wp-includes/cache.php: wp_cache_flush()
  • wp-includes/l10n.php: __()
  • wp-includes/pluggable.php: wp_generate_password()
  • wp-includes/functions.php: wp_guess_url()
  • wp-includes/functions.php: _deprecated_argument()
  • wp-includes/plugin.php: do_action()
  • wp-includes/option.php: update_option()
  • wp-includes/user.php: wp_create_user()
  • wp-includes/user.php: username_exists()
  • wp-includes/user.php: update_user_option()
  • wp-includes/rewrite.php: flush_rewrite_rules()
  • Show 15 more uses Hide more uses

User Contributed Notes

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

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

发布评论

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