add_new_user_to_blog()
Adds a newly created user to the appropriate blog
To add a user in general, use add_user_to_blog(). This function is specifically hooked into the wpmu_activate_user action.
No Hooks.
Returns
null. Nothing (null).
Usage
add_new_user_to_blog( $user_id, $password, $meta );
- $user_id(int) (required)
- User ID.
- $password(string) (required)
User password. Ignored.
It has the attribute #[\SensitiveParameter], which hides the value of the parameter from logs. It is used to protect sensitive data (for example, passwords). Documentation.
- $meta(array) (required)
- Signup meta data.
Notes
- See: add_user_to_blog()
Changelog
| Since 3.0.0 | Introduced. |
add_new_user_to_blog() add new user to blog code WP 7.0
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 );
}
}
}