wpsc_add_new_user

WPSC add new user function, validates and adds a new user, for the.

Description

(int) wpsc_add_new_user( (string) $user_login, (string) $user_pass, (string) $user_email ); 

Returns (int)

The new user's ID.

Parameters (3)

0. $user_login (string)
The user's username.
1. $user_pass (string)
The user's password.
2. $user_email — Optional. (string)
The user's email (optional).

Usage

  1. if ( !function_exists( 'wpsc_add_new_user' ) ) { 
  2. require_once '/wpsc-includes/misc.functions.php'; 
  3.  
  4. // The user's username. 
  5. $user_login = ''; 
  6.  
  7. // The user's password. 
  8. $user_pass = ''; 
  9.  
  10. // The user's email (optional). 
  11. $user_email = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wpsc_add_new_user($user_login, $user_pass, $user_email); 
  15.  

Defined (1)

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

/wpsc-includes/misc.functions.php  
  1. function wpsc_add_new_user( $user_login, $user_pass, $user_email ) { 
  2. $errors = new WP_Error(); 
  3. $user_login = sanitize_user( $user_login ); 
  4. $user_email = apply_filters( 'user_registration_email', $user_email ); 
  5.  
  6. // Check the username 
  7. if ( $user_login == '' ) { 
  8. $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.', 'wpsc' ) ); 
  9. } elseif ( !validate_username( $user_login ) ) { 
  10. $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.', 'wpsc' ) ); 
  11. $user_login = ''; 
  12. } elseif ( username_exists( $user_login ) ) { 
  13. $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered, please choose another one.', 'wpsc' ) ); 
  14.  
  15. // Check the e-mail address 
  16. if ( $user_email == '' ) { 
  17. $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your e-mail address.', 'wpsc' ) ); 
  18. } elseif ( !is_email( $user_email ) ) { 
  19. $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn’t correct.', 'wpsc' ) ); 
  20. $user_email = ''; 
  21. } elseif ( email_exists( $user_email ) ) { 
  22. $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.', 'wpsc' ) ); 
  23.  
  24. if ( $errors->get_error_code() ) { 
  25. return $errors; 
  26. $user_id = wp_create_user( $user_login, $user_pass, $user_email ); 
  27. if ( !$user_id ) { 
  28. $errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'wpsc' ), get_option( 'admin_email' ) ) ); 
  29. return $errors; 
  30.  
  31. $user = wp_signon( array( 'user_login' => $user_login, 'user_password' => $user_pass, 'remember' => true ) ); 
  32. wp_set_current_user( $user->ID ); 
  33.  
  34. return $user;