bb_new_user

The BuddyPress bb new user function.

Description

Parameters (4)

0. $user_login
The user login.
1. $user_email
The user email.
2. $user_url
The user url.
3. $user_status — Optional. (int) => 1
The user status.

Usage

  1. if ( !function_exists( 'bb_new_user' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-pluggable.php'; 
  3.  
  4. // The user login. 
  5. $user_login = null; 
  6.  
  7. // The user email. 
  8. $user_email = null; 
  9.  
  10. // The user url. 
  11. $user_url = null; 
  12.  
  13. // The user status. 
  14. $user_status = 1; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = bb_new_user($user_login, $user_email, $user_url, $user_status); 
  18.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-pluggable.php  
  1. function bb_new_user( $user_login, $user_email, $user_url, $user_status = 1 ) { 
  2. global $wp_users_object, $bbdb; 
  3.  
  4. // is_email check + dns 
  5. if ( !$user_email = is_email( $user_email ) ) 
  6. return new WP_Error( 'user_email', __( 'Invalid email address' ), $user_email ); 
  7.  
  8. if ( !$user_login = sanitize_user( $user_login, true ) ) 
  9. return new WP_Error( 'user_login', __( 'Invalid username' ), $user_login ); 
  10.  
  11. // user_status = 1 means the user has not yet been verified 
  12. $user_status = is_numeric($user_status) ? (int) $user_status : 1; 
  13. if ( defined( 'BB_INSTALLING' ) ) 
  14. $user_status = 0; 
  15.  
  16. $user_nicename = $_user_nicename = bb_user_nicename_sanitize( $user_login ); 
  17. if ( strlen( $_user_nicename ) < 1 ) 
  18. return new WP_Error( 'user_login', __( 'Invalid username' ), $user_login ); 
  19.  
  20. while ( is_numeric($user_nicename) || $existing_user = bb_get_user_by_nicename( $user_nicename ) ) 
  21. $user_nicename = bb_slug_increment($_user_nicename, $existing_user->user_nicename, 50); 
  22.  
  23. $user_url = $user_url ? bb_fix_link( $user_url ) : ''; 
  24.  
  25. $user_pass = bb_generate_password(); 
  26.  
  27. $user = $wp_users_object->new_user( compact( 'user_login', 'user_email', 'user_url', 'user_nicename', 'user_status', 'user_pass' ) ); 
  28. if ( is_wp_error($user) ) { 
  29. if ( 'user_nicename' == $user->get_error_code() ) 
  30. return new WP_Error( 'user_login', $user->get_error_message() ); 
  31. return $user; 
  32.  
  33. if (BB_INSTALLING) { 
  34. bb_update_usermeta( $user['ID'], $bbdb->prefix . 'capabilities', array('keymaster' => true) ); 
  35. } else { 
  36. bb_update_usermeta( $user['ID'], $bbdb->prefix . 'capabilities', array('member' => true) ); 
  37. bb_send_pass( $user['ID'], $user['plain_pass'] ); 
  38.  
  39. do_action('bb_new_user', $user['ID'], $user['plain_pass']); 
  40. return $user['ID'];