wpmu_create_user() WordPress Function

The wpmu_create_user() function is used to create a new user in a WordPress Multisite installation. This function is only available in WordPress Multisite.

wpmu_create_user( string $user_name, string $password, string $email ) #

Creates a user.


Description

This function runs when a user self-registers as well as when a Super Admin creates a new user. Hook to ‘wpmu_new_user’ for events that should affect all new users, but only on Multisite (otherwise use ‘user_register’).


Top ↑

Parameters

$user_name

(string)(Required)The new user's login name.

$password

(string)(Required)The new user's password.

$email

(string)(Required)The new user's email address.


Top ↑

Return

(int|false) Returns false on failure, or int $user_id on success


Top ↑

Source

File: wp-includes/ms-functions.php

function wpmu_create_user( $user_name, $password, $email ) {
	$user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) );

	$user_id = wp_create_user( $user_name, $password, $email );
	if ( is_wp_error( $user_id ) ) {
		return false;
	}

	// Newly created users have no roles or caps until they are added to a blog.
	delete_user_option( $user_id, 'capabilities' );
	delete_user_option( $user_id, 'user_level' );

	/**
	 * Fires immediately after a new user is created.
	 *
	 * @since MU (3.0.0)
	 *
	 * @param int $user_id User ID.
	 */
	do_action( 'wpmu_new_user', $user_id );

	return $user_id;
}


Top ↑

Changelog

Changelog
VersionDescription
MU (3.0.0)Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More