Codex

Function Reference/wp create user

Contents

Description

The wp_create_user function allows you to insert a new user into the WordPress database by parsing 3 (three) parameters through to the function itself. It uses the $wpdb class to escape the variable values, preparing it for insertion into the database. Then the PHP compact() function is used to create an array with these values.

Note: To execute this function you will need to add this line of code: require_once(ABSPATH . WPINC . '/registration.php'); in order to define the function.

Usage

 <?php wp_create_user($username$password$email ); ?> 

Example

As used in wp-admin/upgrade-functions.php:

$user_id = username_exists( $user_name );
if ( !$user_id ) {
	$random_password = wp_generate_password( 12, false );
	$user_id = wp_create_user( $user_name, $random_password, $user_email );
} else {
	$random_password = __('User already exists.  Password inherited.');
}

Parameters

$username
(string) (required) The username of the user to be created.
Default: None
$password
(string) (required) The password of the user to be created.
Default: None
$email
(string) (optional) The email address of the user to be created.
Default: None

Returns

This function returns the user ID of the created user.

This article is marked as in need of editing. You can help Codex by editing it.