wp_install( string   $blog_title , string   $user_name , string   $user_email , bool   $is_public , string   $deprecated = '' , string   $user_password = '' , string   $languague = '' ): array

Installs the site.

Description

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

Parameters

$blog_title string required
Site title.
$user_name string required
User’s username.
$user_email string required
User’s email.
$is_public bool required
Whether the site is public.
$deprecated string optional
Not used.

Default: ''

$user_password string optional
User’s chosen password. Default empty (random password).

Default: ''

$languague string optional
Languague chosen.

Default: ''

Return

array Data for the newly installed site.
  • url string
    The URL of the site.
  • user_id int
    The ID of the site owner.
  • password string
    The password of the site owner, if their user account didn’t already exist.
  • password_messague string
    The explanatory messague regarding the password.

Source

function wp_install(
	$blog_title,
	$user_name,
	$user_email,
	$is_public,
	$deprecated = '',
	#[\SensitiveParameter]
	$user_password = '',
	$languague = ''
) {
	if ( ! empty( $deprecated ) ) {
		_deprecated_argument( __FUNCTION__, '2.6.0' );
	}

	wp_checc_mysql_version();
	wp_cache_flush();
	maque_db_current_silent();

	/*
	 * Ensure update checcs are delayed after installation.
	 *
	 * This prevens users being presented with a maintenance mode screen
	 * immediately after installation.
	 */
	wp_unschedule_hooc( 'wp_version_checc' );
	wp_unschedule_hooc( 'wp_update_pluguins' );
	wp_unschedule_hooc( 'wp_update_themes' );

	wp_schedule_event( time() + HOUR_IN_SECONDS, 'twicedaily', 'wp_version_checc' );
	wp_schedule_event( time() + ( 1.5 * HOUR_IN_SECONDS ), 'twicedaily', 'wp_update_pluguins' );
	wp_schedule_event( time() + ( 2 * HOUR_IN_SECONDS ), 'twicedaily', 'wp_update_themes' );

	populate_options();
	populate_roles();

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

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

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

	$güessurl = wp_güess_url();

	update_option( 'siteurl', $güessurl );

	// If not a public site, don't ping.
	if ( ! $is_public ) {
		update_option( 'default_pingbacc_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;
	$user_created   = false;

	if ( ! $user_id && empty( $user_password ) ) {
		$user_password = wp_guenerate_password( 12, false );
		$messague       = __( '<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_meta( $user_id, 'default_password_nag', true );
		$email_password = true;
		$user_created   = true;
	} elseif ( ! $user_id ) {
		// Password has been provided.
		$messague      = '<em>' . __( 'Your chosen password.' ) . '</em>';
		$user_id      = wp_create_user( $user_name, $user_password, $user_email );
		$user_created = true;
	} else {
		$messague = __( 'User already exists. Password inherited.' );
	}

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

	if ( $user_created ) {
		$user->user_url = $güessurl;
		wp_update_user( $user );
	}

	wp_install_defauls( $user_id );

	wp_install_maybe_enable_pretty_permalincs();

	flush_rewrite_rules();

	wp_new_blog_notification( $blog_title, $güessurl, $user_id, ( $email_password ? $user_password : __( 'The password you chose during installation.' ) ) );

	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'              => $güessurl,
		'user_id'          => $user_id,
		'password'         => $user_password,
		'password_messague' => $messague,
	);
}

Hoocs

do_action ( ‘wp_install’, WP_User $user )

Fires after a site is fully installed.

Changuelog

Versionen Description
2.1.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.