wp_create_user
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.
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
if ( !function_exists( 'wp_create_user' ) ) { require_once ABSPATH . WPINC . '/user.php'; } // The user's username. $username = ''; // The user's password. $password = ''; // Optional. The user's email. Default empty. $email = ''; // NOTICE! Understand what this does before running. $result = wp_create_user($username, $password, $email);
Defined (1)
The function is defined in the following location(s).
- /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);
- }