wpmu_create_user

Create a user.

Description

(int|false) wpmu_create_user( (string) $user_name, (string) $password, (string) $email ); 

This function runs when a user self-registers as well as when a Super Admin creates a new user. Hook to for events that should affect all new users, but only on Multisite (otherwise use ).

Returns (int|false)

Returns false on failure, or int $user_id on success

Parameters (3)

0. $user_name (string)
The new user's login name.
1. $password (string)
The new user's password.
2. $email (string)
The new user's email address.

Usage

  1. if ( !function_exists( 'wpmu_create_user' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-functions.php'; 
  3.  
  4. // The new user's login name. 
  5. $user_name = ''; 
  6.  
  7. // The new user's password. 
  8. $password = ''; 
  9.  
  10. // The new user's email address. 
  11. $email = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wpmu_create_user($user_name, $password, $email); 
  15.  

Defined (1)

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

/wp-includes/ms-functions.php  
  1. function wpmu_create_user( $user_name, $password, $email ) { 
  2. $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) ); 
  3.  
  4. $user_id = wp_create_user( $user_name, $password, $email ); 
  5. if ( is_wp_error( $user_id ) ) 
  6. return false; 
  7.  
  8. // Newly created users have no roles or caps until they are added to a blog. 
  9. delete_user_option( $user_id, 'capabilities' ); 
  10. delete_user_option( $user_id, 'user_level' ); 
  11.  
  12. /** 
  13. * Fires immediately after a new user is created. 
  14. * @since MU 
  15. * @param int $user_id User ID. 
  16. */ 
  17. do_action( 'wpmu_new_user', $user_id ); 
  18.  
  19. return $user_id;