wpmu_activate_signup

The timeline below displays how wordpress function wpmu_activate_signup has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Activates a signup.
 *
 * Hook to {@see 'wpmu_activate_user'} or {@see '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).
 *
 * @since MU (3.0.0)
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $key The activation key provided to the user.
 * @return array|WP_Error An array containing information about the activated user and/or blog.
 */
function wpmu_activate_signup($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);
            $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    /**
     * Fires immediately after a site is activated.
     *
     * @since MU (3.0.0)
     *
     * @param int    $blog_id       Blog ID.
     * @param int    $user_id       User ID.
     * @param string $password      User password.
     * @param string $signup_title  Site title.
     * @param array  $meta          Signup meta data. By default, contains the requested privacy setting and lang_id.
     */
    do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}

WordPress Version: 6.1

/**
 * Activates a signup.
 *
 * Hook to {@see 'wpmu_activate_user'} or {@see '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).
 *
 * @since MU (3.0.0)
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $key The activation key provided to the user.
 * @return array|WP_Error An array containing information about the activated user and/or blog
 */
function wpmu_activate_signup($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);
            $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    /**
     * Fires immediately after a site is activated.
     *
     * @since MU (3.0.0)
     *
     * @param int    $blog_id       Blog ID.
     * @param int    $user_id       User ID.
     * @param string $password      User password.
     * @param string $signup_title  Site title.
     * @param array  $meta          Signup meta data. By default, contains the requested privacy setting and lang_id.
     */
    do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}

WordPress Version: 5.9

/**
 * Activate a signup.
 *
 * Hook to {@see 'wpmu_activate_user'} or {@see '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).
 *
 * @since MU (3.0.0)
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $key The activation key provided to the user.
 * @return array|WP_Error An array containing information about the activated user and/or blog
 */
function wpmu_activate_signup($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);
            $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    /**
     * Fires immediately after a site is activated.
     *
     * @since MU (3.0.0)
     *
     * @param int    $blog_id       Blog ID.
     * @param int    $user_id       User ID.
     * @param string $password      User password.
     * @param string $signup_title  Site title.
     * @param array  $meta          Signup meta data. By default, contains the requested privacy setting and lang_id.
     */
    do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}

WordPress Version: 5.5

/**
 * Activate a signup.
 *
 * Hook to {@see 'wpmu_activate_user'} or {@see '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).
 *
 * @since MU (3.0.0)
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $key The activation key provided to the user.
 * @return array|WP_Error An array containing information about the activated user and/or blog
 */
function wpmu_activate_signup($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);
            $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    /**
     * Fires immediately after a site is activated.
     *
     * @since MU (3.0.0)
     *
     * @param int    $blog_id       Blog ID.
     * @param int    $user_id       User ID.
     * @param int    $password      User password.
     * @param string $signup_title  Site title.
     * @param array  $meta          Signup meta data. By default, contains the requested privacy setting and lang_id.
     */
    do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}

WordPress Version: 5.4

/**
 * Activate a signup.
 *
 * Hook to {@see 'wpmu_activate_user'} or {@see '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).
 *
 * @since MU (3.0.0)
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $key The activation key provided to the user.
 * @return array|WP_Error An array containing information about the activated user and/or blog
 */
function wpmu_activate_signup($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);
            $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    /**
     * Fires immediately after a site is activated.
     *
     * @since MU (3.0.0)
     *
     * @param int    $blog_id       Blog ID.
     * @param int    $user_id       User ID.
     * @param int    $password      User password.
     * @param string $signup_title  Site title.
     * @param array  $meta          Signup meta data. By default, contains the requested privacy setting and lang_id.
     */
    do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}

WordPress Version: 4.9

/**
 * Activate a signup.
 *
 * Hook to {@see 'wpmu_activate_user'} or {@see '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).
 *
 * @since MU (3.0.0)
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $key The activation key provided to the user.
 * @return array|WP_Error An array containing information about the activated user and/or blog
 */
function wpmu_activate_signup($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 int   $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);
            $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    /**
     * Fires immediately after a site is activated.
     *
     * @since MU (3.0.0)
     *
     * @param int    $blog_id       Blog ID.
     * @param int    $user_id       User ID.
     * @param int    $password      User password.
     * @param string $signup_title  Site title.
     * @param array  $meta          Signup meta data. By default, contains the requested privacy setting and lang_id.
     */
    do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}

WordPress Version: 4.8

/**
 * Activate a signup.
 *
 * Hook to {@see 'wpmu_activate_user'} or {@see '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).
 *
 * @since MU
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $key The activation key provided to the user.
 * @return array|WP_Error An array containing information about the activated user and/or blog
 */
function wpmu_activate_signup($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
         *
         * @param int   $user_id  User ID.
         * @param int   $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, $wpdb->siteid);
    // 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);
            $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    /**
     * Fires immediately after a site is activated.
     *
     * @since MU
     *
     * @param int    $blog_id       Blog ID.
     * @param int    $user_id       User ID.
     * @param int    $password      User password.
     * @param string $signup_title  Site title.
     * @param array  $meta          Signup meta data. By default, contains the requested privacy setting and lang_id.
     */
    do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}

WordPress Version: 4.6

/**
 * Activate a signup.
 *
 * Hook to {@see 'wpmu_activate_user'} or {@see '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).
 *
 * @since MU
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $key The activation key provided to the user.
 * @return array|WP_Error An array containing information about the activated user and/or blog
 */
function wpmu_activate_signup($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
         *
         * @param int   $user_id  User ID.
         * @param int   $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, $wpdb->siteid);
    // 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);
            $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    /**
     * Fires immediately after a site is activated.
     *
     * @since MU
     *
     * @param int    $blog_id       Blog ID.
     * @param int    $user_id       User ID.
     * @param int    $password      User password.
     * @param string $signup_title  Site title.
     * @param array  $meta          Signup meta data.
     */
    do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}

WordPress Version: 4.4

/**
 * Activate a signup.
 *
 * 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).
 *
 * @since MU
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $key The activation key provided to the user.
 * @return array|WP_Error An array containing information about the activated user and/or blog
 */
function wpmu_activate_signup($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
         *
         * @param int   $user_id  User ID.
         * @param int   $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, $wpdb->siteid);
    // 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);
            $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    /**
     * Fires immediately after a site is activated.
     *
     * @since MU
     *
     * @param int    $blog_id       Blog ID.
     * @param int    $user_id       User ID.
     * @param int    $password      User password.
     * @param string $signup_title  Site title.
     * @param array  $meta          Signup meta data.
     */
    do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}

WordPress Version: 4.3

/**
 * Activate a signup.
 *
 * 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).
 *
 * @since MU
 *
 * @global wpdb $wpdb
 *
 * @param string $key The activation key provided to the user.
 * @return array|WP_Error An array containing information about the activated user and/or blog
 */
function wpmu_activate_signup($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);
        }
        wpmu_welcome_user_notification($user_id, $password, $meta);
        /**
         * Fires immediately after a new user is activated.
         *
         * @since MU
         *
         * @param int   $user_id  User ID.
         * @param int   $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, $wpdb->siteid);
    // 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);
            $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    wpmu_welcome_notification($blog_id, $user_id, $password, $signup->title, $meta);
    /**
     * Fires immediately after a site is activated.
     *
     * @since MU
     *
     * @param int    $blog_id       Blog ID.
     * @param int    $user_id       User ID.
     * @param int    $password      User password.
     * @param string $signup_title  Site title.
     * @param array  $meta          Signup meta data.
     */
    do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}

WordPress Version: 4.1

/**
 * Activate a signup.
 *
 * 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).
 *
 * @since MU
 *
 * @param string $key The activation key provided to the user.
 * @return array An array containing information about the activated user and/or blog
 */
function wpmu_activate_signup($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);
        }
        wpmu_welcome_user_notification($user_id, $password, $meta);
        /**
         * Fires immediately after a new user is activated.
         *
         * @since MU
         *
         * @param int   $user_id  User ID.
         * @param int   $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, $wpdb->siteid);
    // 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);
            $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    wpmu_welcome_notification($blog_id, $user_id, $password, $signup->title, $meta);
    /**
     * Fires immediately after a site is activated.
     *
     * @since MU
     *
     * @param int    $blog_id       Blog ID.
     * @param int    $user_id       User ID.
     * @param int    $password      User password.
     * @param string $signup_title  Site title.
     * @param array  $meta          Signup meta data.
     */
    do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}

WordPress Version: 3.8

/**
 * Activate a signup.
 *
 * 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).
 *
 * @since MU
 * @uses wp_generate_password()
 * @uses wpmu_welcome_user_notification()
 * @uses add_user_to_blog()
 * @uses wpmu_create_user()
 * @uses wpmu_create_blog()
 * @uses wpmu_welcome_notification()
 *
 * @param string $key The activation key provided to the user.
 * @return array An array containing information about the activated user and/or blog
 */
function wpmu_activate_signup($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);
        }
        wpmu_welcome_user_notification($user_id, $password, $meta);
        /**
         * Fires immediately after a new user is activated.
         *
         * @since MU
         *
         * @param int   $user_id  User ID.
         * @param int   $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, $wpdb->siteid);
    // 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);
            $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    wpmu_welcome_notification($blog_id, $user_id, $password, $signup->title, $meta);
    /**
     * Fires immediately after a site is activated.
     *
     * @since MU
     *
     * @param int    $blog_id       Blog ID.
     * @param int    $user_id       User ID.
     * @param int    $password      User password.
     * @param string $signup_title  Site title.
     * @param array  $meta          Signup meta data.
     */
    do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}

WordPress Version: 3.7

/**
 * Activate a signup.
 *
 * 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).
 *
 * @since MU
 * @uses wp_generate_password()
 * @uses wpmu_welcome_user_notification()
 * @uses add_user_to_blog()
 * @uses wpmu_create_user()
 * @uses wpmu_create_blog()
 * @uses wpmu_welcome_notification()
 *
 * @param string $key The activation key provided to the user.
 * @return array An array containing information about the activated user and/or blog
 */
function wpmu_activate_signup($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);
        }
        wpmu_welcome_user_notification($user_id, $password, $meta);
        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, $wpdb->siteid);
    // 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);
            $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    wpmu_welcome_notification($blog_id, $user_id, $password, $signup->title, $meta);
    do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}