wpmu_activate_signup( string $key ): array|WP_Error
- Since
- MU (3.0.0)
- Source
wp-includes/ms-functions.php:1205
Description
Hook to 'wpmu_activate_user' or 'wpmu_activate_blog' for events that should happen only when users or sites are self-created (since those actions are not called when users and sites are created by a Super Admin).
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
$keystring- The activation key provided to the user.
Return value
array|WP_Error- An array containing information about the activated user and/or blog.
Performance profile
How much work a call to wpmu_activate_signup() 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
- Heavy
- Scaling
- Constant
- Instructions
- 24–107
- Plugin surface
- 2 hooks
- Called by
- 0
Reaches the database via ->get_row().
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 195.
Third-party callbacks on 'wpmu_activate_user', 'wpmu_activate_blog' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- serializeserialisation
maybe_unserialize()called directly - hookthird-party callbacks
do_action()called directly - sqldatabase query
->get_row()called directly - querycontent query
get_user_by()one call below wpmu_activate_signup() - optionoption read or write
get_option()one call below wpmu_activate_signup() - cacheobject cache
wp_cache_set_sites_last_changed()one call below wpmu_activate_signup()
Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 25 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wpmu_activate_signup() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 24–29 | ->prepare(), ->get_row(), __() |
!empty($signup) && !$signup | 45 | ->prepare(), ->get_row(), wp_generate_password(), username_exists(), __() |
!empty($signup) && !$signup | 51 | ->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), __() |
!empty($signup) && !$signup | 55 | ->prepare(), ->get_row(), wp_generate_password(), username_exists(), wpmu_create_user(), __() |
!empty($signup) && !$signup | 61 | ->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), wpmu_create_user(), __() |
!$signup && isset($user_already_exists) | 64 | ->prepare(), ->get_row(), wp_generate_password(), username_exists(), current_time(), activation_key(), __(), active() |
!$signup && !isset($user_already_exists) | 65 | ->prepare(), ->get_row(), wp_generate_password(), username_exists(), current_time(), activation_key(), do_action() |
!empty($signup) && !$signup && is_wp_error() | 69 | ->prepare(), ->get_row(), wp_generate_password(), username_exists(), current_time(), get_current_network_id(), wpmu_create_blog(), is_wp_error(), ->get_error_code() |
!$signup && isset($user_already_exists) | 70 | ->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), current_time(), activation_key(), __(), active() |
!$signup && !isset($user_already_exists) | 71 | ->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), current_time(), activation_key(), do_action() |
!$signup && isset($user_already_exists) | 74 | ->prepare(), ->get_row(), wp_generate_password(), username_exists(), wpmu_create_user(), current_time(), activation_key(), __(), active() |
!$signup && !isset($user_already_exists) | 75 | ->prepare(), ->get_row(), wp_generate_password(), username_exists(), wpmu_create_user(), current_time(), activation_key(), do_action() |
13 further outcomes, up to 107 instructions
!empty($signup) && !$signup && is_wp_error() | 75 | ->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), current_time(), get_current_network_id(), wpmu_create_blog(), is_wp_error(), ->get_error_code() |
!empty($signup) && !$signup && is_wp_error() | 79 | ->prepare(), ->get_row(), wp_generate_password(), username_exists(), wpmu_create_user(), current_time(), get_current_network_id(), wpmu_create_blog(), is_wp_error(), ->get_error_code() |
!$signup && isset($user_already_exists) | 80 | ->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), wpmu_create_user(), current_time(), activation_key(), __(), active() |
!$signup && !isset($user_already_exists) | 81 | ->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), wpmu_create_user(), current_time(), activation_key(), do_action() |
!empty($signup) && !$signup && is_wp_error() | 82 | ->prepare(), ->get_row(), wp_generate_password(), username_exists(), current_time(), get_current_network_id(), wpmu_create_blog(), is_wp_error(), ->get_error_code(), ->add_data(), activation_key() |
!empty($signup) && !$signup && is_wp_error() | 85 | ->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), wpmu_create_user(), current_time(), get_current_network_id(), wpmu_create_blog(), is_wp_error(), ->get_error_code() |
!empty($signup) && !$signup && is_wp_error() | 88 | ->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), current_time(), get_current_network_id(), wpmu_create_blog(), is_wp_error(), ->get_error_code(), ->add_data(), activation_key() |
!empty($signup) && !$signup && !is_wp_error() | 91 | ->prepare(), ->get_row(), wp_generate_password(), username_exists(), current_time(), get_current_network_id(), wpmu_create_blog(), is_wp_error(), activation_key(), do_action() |
!empty($signup) && !$signup && is_wp_error() | 92 | ->prepare(), ->get_row(), wp_generate_password(), username_exists(), wpmu_create_user(), current_time(), get_current_network_id(), wpmu_create_blog(), is_wp_error(), ->get_error_code(), ->add_data(), activation_key() |
!empty($signup) && !$signup && !is_wp_error() | 97 | ->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), current_time(), get_current_network_id(), wpmu_create_blog(), is_wp_error(), activation_key(), do_action() |
!empty($signup) && !$signup && is_wp_error() | 98 | ->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), wpmu_create_user(), current_time(), get_current_network_id(), wpmu_create_blog(), is_wp_error(), ->get_error_code(), ->add_data(), activation_key() |
!empty($signup) && !$signup && !is_wp_error() | 101 | ->prepare(), ->get_row(), wp_generate_password(), username_exists(), wpmu_create_user(), current_time(), get_current_network_id(), wpmu_create_blog(), is_wp_error(), activation_key(), do_action() |
!empty($signup) && !$signup && !is_wp_error() | 107 | ->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), wpmu_create_user(), current_time(), get_current_network_id(), wpmu_create_blog(), is_wp_error(), activation_key(), do_action() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 195 instructions, 24–107 executed per call, 10 branches. The work does not change between versions.
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 · 2
2 hooks fire while wpmu_activate_signup() runs, in this order:
- do_action( wpmu_activate_user )actionline 1271 (+66 into the body)
Fires immediately after a new user is activated.
- do_action( wpmu_activate_blog )actionline 1323 (+118 into the body)
Fires immediately after a site is activated.
Uses · 11
- __()Retrieves the translation of $text.
- maybe_unserialize()Unserializes data only if it was serialized.
- wp_generate_password()Generates a random password drawn from the defined set of characters.
- username_exists()Determines whether the given username exists.
- wpmu_create_user()Creates a user.
- current_time()Retrieves the current time based on specified type.
- do_action()Calls the callback functions that have been added to an action hook.
- wpmu_create_blog()Creates a site.
- get_current_network_id()Retrieves the current network ID.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- WP_Error::__construct()Initializes the error.
Source code
function wpmu_activate_signup( #[\SensitiveParameter] $key) { global $wpdb; /** @var object{ signup_id: string, domain: string, path: string, title: string, user_login: string, user_email: string, registered: string, activated: string, active: string, activation_key: string, meta: string|null }|null $signup */ $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key ) ); if ( empty( $signup ) ) { return new WP_Error( 'invalid_key', __( 'Invalid activation key.' ) ); } if ( $signup->active ) { if ( empty( $signup->domain ) ) { return new WP_Error( 'already_active', __( 'The user is already active.' ), $signup ); } else { return new WP_Error( 'already_active', __( 'The site is already active.' ), $signup ); } } if ( is_string( $signup->meta ) ) { /** @var array<string, mixed> $meta */ $meta = maybe_unserialize( $signup->meta ); } else { $meta = array(); } $password = wp_generate_password( 12, false ); $user_id = username_exists( $signup->user_login ); if ( ! $user_id ) { $user_id = wpmu_create_user( $signup->user_login, $password, $signup->user_email ); } else { $user_already_exists = true; } if ( ! $user_id ) { return new WP_Error( 'create_user', __( 'Could not create user' ), $signup ); } $now = current_time( 'mysql', true ); if ( empty( $signup->domain ) ) { $wpdb->update( (string) $wpdb->signups, array( 'active' => 1, 'activated' => $now, ), array( 'activation_key' => $key ) ); if ( isset( $user_already_exists ) ) { return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup ); } /** * Fires immediately after a new user is activated. * * @since MU (3.0.0) * * @param int $user_id User ID. * @param string $password User password. * @param array $meta Signup meta data. */ do_action( 'wpmu_activate_user', $user_id, $password, $meta ); return array( 'user_id' => $user_id, 'password' => $password, 'meta' => $meta, ); } $blog_id = wpmu_create_blog( $signup->domain, $signup->path, $signup->title, $user_id, $meta, get_current_network_id() ); // TODO: What to do if we create a user but cannot create a blog? if ( is_wp_error( $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 7.1.0 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.