Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/register new user


The register_new_user() function inserts a new user into the WordPress database. This function is used when a new user registers through WordPress' Login Page. It differs from wp_create_user() in that it requires a valid username and email address but doesn't allow to chose a password, generating a random one using wp_generate_password(). If you want to create a new user with a specific password or with additional parameters, use wp_create_user() or wp_insert_user() instead.

register_new_user() doesn't handle the user creation itself, it simply checks the submitted username and email validity and generates a random password, relying on wp_create_user() to create the new User. If registration worked it sends a notification email to the user with his password using wp_new_user_notification(). In case of registration failure it returns a WP_Error().

register_new_user() also provides two useful hooks to customize validation rules or user registration process, register_post and registration_errors.


 <?php register_new_user$user_login$user_email ); ?> 


As used in wp-login.php:

$user_login = $_POST['user_login'];
$user_email = $_POST['user_email'];
$errors = register_new_user($user_login, $user_email);
if ( !is_wp_error($errors) ) {
	$redirect_to = !empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : 'wp-login.php?checkemail=registered';
	wp_safe_redirect( $redirect_to );


(string) (required) User's username for logging in
Default: None
(string) (required) User's email address to send password and add
Default: None


Like wp_create_user(), when successful this function returns the user ID of the created user. In case of failure (login or email is empty, invalid, already existing, or wp_create_user() failed) the function returns an error object.

Source File

register_new_user() is located in wp-includes/user.php.

See also index of Function Reference and index of Template Tags.