wppaste
WordPress

wpmu_activate_signup( string $key ): array|WP_Error

Since
MU (3.0.0)
Source
wp-includes/ms-functions.php:1193
Activates a signup.

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

Reaches the database via ->get_row().

Scaling
Constant

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

Instructions
24–103

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

Plugin surface
2 hooks

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

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • serializeserialisationmaybe_unserialize()called directly
  • hookthird-party callbacksdo_action()called directly
  • sqldatabase query->get_row()called directly
  • querycontent queryget_user_by()one call below wpmu_activate_signup()
  • optionoption read or writeget_option()one call below wpmu_activate_signup()
  • cacheobject cachewp_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 · 13 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.

WhenInstructionsCalls it makes
always24–29->prepare(), ->get_row(), __()
!empty($signup) && !$signup47->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), __()
!empty($signup) && !$signup57->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), wpmu_create_user(), __()
!$signup && isset($user_already_exists)66->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), current_time(), activation_key(), __(), active()
!$signup && !isset($user_already_exists)67->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), current_time(), activation_key(), do_action()
!empty($signup) && !$signup && is_wp_error()71->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()
!$signup && isset($user_already_exists)76->prepare(), ->get_row(), maybe_unserialize(), wp_generate_password(), username_exists(), wpmu_create_user(), current_time(), activation_key(), __(), active()
!$signup && !isset($user_already_exists)77->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()81->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()84->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()93->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()94->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()
1 further outcome, up to 103 instructions
!empty($signup) && !$signup && !is_wp_error()103->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: 190 instructions, 24–103 executed per call, 9 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:

  1. do_action( wpmu_activate_user )actionline 1253 (+60 into the body)

    Fires immediately after a new user is activated.

  2. do_action( wpmu_activate_blog )actionline 1305 (+112 into the body)

    Fires immediately after a site is activated.

Uses · 11

Source code

function wpmu_activate_signup(	#[\SensitiveParameter]	$key) {	global $wpdb; 	$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 );		}	} 	$meta     = maybe_unserialize( $signup->meta );	$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(			$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 ) ) {		/*		 * If blog is taken, that means a previous attempt to activate this blog		 * failed in between creating the blog and setting the activation flag.		 * Let's just set the active flag and instruct the user to reset their password.		 */		if ( 'blog_taken' === $blog_id->get_error_code() ) {			$blog_id->add_data( $signup );

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.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.