Adding a new user to BuddyPress in code

//**********************************
//**********************************
//********** ADD NEW USER **********
//**********************************
//**********************************
function add_a_new_user ($added_by_user_id, $user_name, $user_password, $user_email)
{
  
  //Use the BuddyPress new user creation process
  $user_id = bp_core_signup_user($user_name, $user_password, $user_email, array());
  if (is_wp_error($user_id))
  {
    //USER COULD NOT BE CREATED 
    return(False);
  }

  
  //----- USER WAS CREATED -----
  
  //SET MEMBER TYPE (optional)
  bp_set_member_type($user_id, 'my_custom_member_type');

  //SET NEW USER TO BE A FRIEND OF THIS USER (optional)
  friends_add_friend($added_by_user_id, $user_id, true);    //$force_accept = true
  
  return($user_id);
}
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *