wppaste
WordPress

wpmu_create_user( string $user_name, string $password, string $email ): int|false

Since
MU (3.0.0)
Source
wp-includes/ms-functions.php:1314
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').

Compatibility

WordPress
since MU (3.0.0)
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$user_namestring
The new user's login name.
$passwordstring
The new user's password.
$emailstring
The new user's email address.

Return value

int|false
Returns false on failure, or int $user_id on success.

Performance profile

How much work a call to wpmu_create_user() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
21–33

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 34.

Plugin surface
1 hook

Third-party callbacks on 'wpmu_new_user' run inside this call, and their cost is not bounded by anything here.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()called directly

Further down the call graph this can also reach option, query, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wpmu_create_user() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
is_wp_error()21sanitize_user(), wp_create_user(), is_wp_error()
!is_wp_error()33sanitize_user(), wp_create_user(), is_wp_error(), delete_user_option(), delete_user_option(), do_action()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev3421–331
8.53421–331
8.43421–3313 fewer instructions than PHP 8.3
8.33724–361
8.23724–361
8.13724–361
7.43724–361

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while wpmu_create_user() runs, in this order:

  1. do_action( wpmu_new_user )actionline 1333 (+19 into the body)

    Fires immediately after a new user is created.

Uses · 5

Used by · 2

Source code

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

Changelog

Introduced in MU (3.0.0). Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/ms-functions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.