wp_create_user

A simpler way of inserting a user into the database.

Description

(int|WP_Error) wp_create_user( (string) $username, (string) $password, (string) $email = '' ); 

Creates a new user with just the username, password, and email. For more complex user creation use wp_insert_user() to specify more information.

Returns (int|WP_Error)

The newly created user's ID or a WP_Error object if the user could not be created.

Parameters (3)

0. $username (string)
The user's username.
1. $password (string)
The user's password.
2. $email — Optional. (string) => ''
The user's email. Default empty.

Usage

  1. if ( !function_exists( 'wp_create_user' ) ) { 
  2. require_once ABSPATH . WPINC . '/user.php'; 
  3.  
  4. // The user's username. 
  5. $username = ''; 
  6.  
  7. // The user's password. 
  8. $password = ''; 
  9.  
  10. // Optional. The user's email. Default empty. 
  11. $email = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wp_create_user($username, $password, $email); 
  15.  

Defined (1)

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

/wp-includes/user.php  
  1. function wp_create_user($username, $password, $email = '') { 
  2. $user_login = wp_slash( $username ); 
  3. $user_email = wp_slash( $email ); 
  4. $user_pass = $password; 
  5.  
  6. $userdata = compact('user_login', 'user_email', 'user_pass'); 
  7. return wp_insert_user($userdata);