Codex tools: Log in
Contents |
Insert a user into the database.
Can update a current user or insert a new user based on whether the user's ID is present.
Can be used to update the user's info (see below), set the user's role, and set the user's preference on the use of the rich editor.
Note: As late as 2.7.1, if you are attempting to update the password for the user, this function will not hash the password, thus failing. Use the wp_update_user instead.
<?php wp_insert_user( $userdata ) ?>
Or a WP_Error object if the user could not be created.
Below is an example showing how to update a user's Website profile field
<?php
$user_id = 1;
$website = 'http://wordpress.org';
wp_insert_user( array ('ID' => $user_id, 'user_url' => $website) ) ;
?>
| Field Name | Description | Associated Filter |
|---|---|---|
| ID | An integer that will be used for updating an existing user. | (none) |
| user_pass | A string that contains the plain text password for the user. | pre_user_user_pass |
| user_login | A string that contains the users username for logging in. | pre_user_user_login |
| user_nicename | A string that contains a nicer looking name for the user. The default is the users username. | pre_user_user_nicename |
| user_url | A string containing the users URL for the users web site. | pre_user_user_url |
| user_email | A string containing the users email address. | pre_user_user_email |
| display_name | A string that will be shown on the site. Defaults to users username. It is likely that you will want to change this, for both appearance and security through obscurity (that is if you dont use and delete the default admin user). | pre_user_display_name |
| nickname | The users nickname, defaults to the users username. | pre_user_nickname |
| first_name | The users first name. | pre_user_first_name |
| last_name | The users last name. | pre_user_last_name |
| description | A string containing content about the user. | pre_user_description |
| rich_editing | A string for whether to enable the rich editor or not. False if not empty. | (none) |
| user_registered | The date the user registered. Format is Y-m-d H:i:s. | (none) |
| role | A string used to set the users role. | (none) |
| jabber | Users Jabber account. | (none) |
| aim | Users AOL IM account. | (none) |
| yim | Users Yahoo IM account. | (none) |
When performing an update operation, user_pass should be the hashed password and not the plain text password.
Since: 2.0.0
As of 3.1 wp_insert_user() is located in wp-includes/user.php.
wp_update_user, wp_create_user