add_new_user_to_blog() WordPress Function

This function allows you to add a new user to your blog. You will need to provide the user's email address and their desired role on the blog. The user will be sent an email with a link to set their password.

add_new_user_to_blog( int $user_id, string $password, array $meta ) #

Adds a newly created user to the appropriate blog


Description

To add a user in general, use add_user_to_blog(). This function is specifically hooked into the ‘wpmu_activate_user’ action.

Top ↑

See also


Top ↑

Parameters

$user_id

(int)(Required)User ID.

$password

(string)(Required)User password. Ignored.

$meta

(array)(Required)Signup meta data.


Top ↑

Source

File: wp-includes/ms-functions.php

function add_new_user_to_blog( $user_id, $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 );
		}
	}
}


Top ↑

Changelog

Changelog
VersionDescription
MU (3.0.0)Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More