add_new_user_to_blog( int $user_id, string $password, array $meta )
- Since
- MU (3.0.0)
- Source
wp-includes/ms-functions.php:2309
Description
To add a user in general, use add_user_to_blog(). This function is specifically hooked into the 'wpmu_activate_user' action.
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_idint- User ID.
$passwordstring- User password. Ignored.
$metaarray- Signup meta data.
Performance profile
How much work a call to add_new_user_to_blog() 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
- Light
- Scaling
- Constant
- Instructions
- 6–31
- Plugin surface
- None
- Called by
- 0
Only touches the object cache, via wp_cache_delete().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 31.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()one call below add_new_user_to_blog() - cacheobject cache
wp_cache_delete()one call below add_new_user_to_blog()
Further down the call graph this can also reach option, query, 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 · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost add_new_user_to_blog() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($meta) | 6 | none |
!empty($meta) && is_wp_error() | 26 | get_network(), remove_user_from_blog(), add_user_to_blog(), is_wp_error() |
!empty($meta) && !is_wp_error() | 31 | get_network(), remove_user_from_blog(), add_user_to_blog(), is_wp_error(), update_user_meta() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 31 | 6–31 | 2 | |
| 8.5 | 31 | 6–31 | 2 | |
| 8.4 | 31 | 6–31 | 2 | |
| 8.3 | 31 | 6–31 | 2 | |
| 8.2 | 31 | 6–31 | 2 | |
| 8.1 | 31 | 6–31 | 2 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 32 | 6–32 | 2 |
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.
Uses · 5
- remove_user_from_blog()Removes a user from a blog.
- get_network()Retrieves network data given a network ID or network object.
- add_user_to_blog()Adds a user to a blog, along with specifying the user's role.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- update_user_meta()Updates user meta field based on user ID.
Source code
function add_new_user_to_blog( $user_id, #[\SensitiveParameter] $password, $meta) { if ( ! empty( $meta['add_to_blog'] ) ) { $blog_id = $meta['add_to_blog']; $role = $meta['new_role']; remove_user_from_blog( $user_id, get_network()->site_id ); // Remove user from main blog. $result = add_user_to_blog( $blog_id, $user_id, $role ); if ( ! is_wp_error( $result ) ) { update_user_meta( $user_id, 'primary_blog', $blog_id ); } }}Changelog
Introduced in MU (3.0.0). Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.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.