add_new_user_to_blog

Adds a newly created user to the appropriate blog.

Description

add_new_user_to_blog( (int) $user_id, (mixed) $password, (array) $meta ); 

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

Parameters (3)

0. $user_id (int)
The user id.
1. $password (mixed)
The password.
2. $meta (array)
The meta.

Usage

  1. if ( !function_exists( 'add_new_user_to_blog' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-functions.php'; 
  3.  
  4. // The user id. 
  5. $user_id = -1; 
  6.  
  7. // The password. 
  8. $password = null; 
  9.  
  10. // The meta. 
  11. $meta = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = add_new_user_to_blog($user_id, $password, $meta); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/ms-functions.php  
  1. function add_new_user_to_blog( $user_id, $password, $meta ) { 
  2. if ( !empty( $meta[ 'add_to_blog' ] ) ) { 
  3. $blog_id = $meta[ 'add_to_blog' ]; 
  4. $role = $meta[ 'new_role' ]; 
  5. remove_user_from_blog($user_id, get_network()->site_id); // remove user from main blog. 
  6. add_user_to_blog( $blog_id, $user_id, $role ); 
  7. update_user_meta( $user_id, 'primary_blog', $blog_id );