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);
}
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

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