wp_create_user() WordPress Function

The wp_create_user function is used to create a new user in WordPress. This function takes two arguments: the user's login name and the user's email address. The function will return the new user's ID if the user is successfully created, or false if the user could not be created.

wp_create_user( string $username, string $password, string $email = '' ) #

Provides a simpler way of inserting a user into the database.


Description

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

Top ↑

See also


Top ↑

Parameters

$username

(string)(Required)The user's username.

$password

(string)(Required)The user's password.

$email

(string)(Optional) The user's email.

Default value: ''


Top ↑

Return

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


Top ↑

Source

File: wp-includes/user.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More