wp_create_user()WP 2.0.0

A simpler way of inserting a user into the database.

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

No Hooks.


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


wp_create_user( $username, $password, $email );
$username(string) (required)
The user's username.
$password(string) (required)
The user's password.
The user's email.
Default: ''



#1 Creating a new user

If WordPress can't create a user, it will return WP_Error object — so let's output the error message in this case:

$random_password = wp_generate_password( 12 );
$user_id = wp_create_user( $user_name, $random_password, $user_email );

if ( is_wp_error( $user_id ) ) {
	echo $user_id->get_error_message();
else {
	echo 'User has been created.';



Since 2.0.0 Introduced.

wp_create_user() code WP 6.5.3

function wp_create_user( $username, $password, $email = '' ) {
	$user_login = wp_slash( $username );
	$user_email = wp_slash( $email );
	$user_pass  = $password;

	$userdata = compact( 'user_login', 'user_email', 'user_pass' );
	return wp_insert_user( $userdata );