WordPress.org

Ready to get started?Download WordPress

Codex

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

Difference between revisions of "Function Reference/wp insert user"

(Notes)
(Notes)
Line 52: Line 52:
 
|-valign="top"
 
|-valign="top"
 
| style="font-weight:bold" | user_login
 
| style="font-weight:bold" | user_login
| A string that contains the users username for logging in.
+
| A string that contains the user's username for logging in.
 
| <tt>pre_user_login</tt>
 
| <tt>pre_user_login</tt>
 
|-valign="top"
 
|-valign="top"
 
| style="font-weight:bold" | user_nicename
 
| style="font-weight:bold" | user_nicename
| A string that contains a nicer looking name for the user. The default is the users username.
+
| A string that contains a URL-friendly name for the user. The default is the user's username.
 
| <tt>pre_user_nicename</tt>
 
| <tt>pre_user_nicename</tt>
 
|-valign="top"
 
|-valign="top"
 
| style="font-weight:bold" | user_url
 
| style="font-weight:bold" | user_url
| A string containing the users URL for the users web site.
+
| A string containing the user's URL for the user's web site.
 
| <tt>pre_user_url</tt>
 
| <tt>pre_user_url</tt>
 
|-valign="top"
 
|-valign="top"
 
| style="font-weight:bold" | user_email
 
| style="font-weight:bold" | user_email
| A string containing the users email address.
+
| A string containing the user's email address.
 
| <tt>pre_user_email</tt>
 
| <tt>pre_user_email</tt>
 
|-valign="top"
 
|-valign="top"
 
| style="font-weight:bold" | display_name
 
| style="font-weight:bold" | 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).
+
| A string that will be shown on the site. Defaults to user's 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).
 
| <tt>pre_user_display_name</tt>
 
| <tt>pre_user_display_name</tt>
 
|-valign="top"
 
|-valign="top"
 
| style="font-weight:bold" | nickname
 
| style="font-weight:bold" | nickname
| The users nickname, defaults to the users username.
+
| The user's nickname, defaults to the user's username.
 
| <tt>pre_user_nickname</tt>
 
| <tt>pre_user_nickname</tt>
 
|-valign="top"
 
|-valign="top"
 
| style="font-weight:bold" | first_name
 
| style="font-weight:bold" | first_name
| The users first name.
+
| The user's first name.
 
| <tt>pre_user_first_name</tt>
 
| <tt>pre_user_first_name</tt>
 
|-valign="top"
 
|-valign="top"
 
| style="font-weight:bold" | last_name
 
| style="font-weight:bold" | last_name
| The users last name.
+
| The user's last name.
 
| <tt>pre_user_last_name</tt>
 
| <tt>pre_user_last_name</tt>
 
|-valign="top"
 
|-valign="top"
Line 96: Line 96:
 
|-valign="top"
 
|-valign="top"
 
| style="font-weight:bold" | role
 
| style="font-weight:bold" | role
| A string used to set the users role.
+
| A string used to set the user's role.
 
| (none)
 
| (none)
 
|-valign="top"
 
|-valign="top"
 
| style="font-weight:bold" | jabber
 
| style="font-weight:bold" | jabber
| Users Jabber account.
+
| User's Jabber account.
 
| (none)
 
| (none)
 
|-valign="top"
 
|-valign="top"
 
| style="font-weight:bold" | aim
 
| style="font-weight:bold" | aim
| Users AOL IM account.
+
| User's AOL IM account.
 
| (none)
 
| (none)
 
|-valign="top"
 
|-valign="top"
 
| style="font-weight:bold" | yim
 
| style="font-weight:bold" | yim
| Users Yahoo IM account.
+
| User's Yahoo IM account.
 
| (none)
 
| (none)
 
|}
 
|}

Revision as of 09:25, 30 July 2012

Description

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.

Usage

<?php wp_insert_user$userdata ?>

Parameters

$userdata
(array) (required) An array of user data.
Default: None

Return Values

(integer) 
The newly created user's ID.

Or a WP_Error object if the user could not be created.

Examples

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

Notes

  • Uses: $wpdb WordPress database layer.
  • Uses: apply_filters() Calls filters for most of the $userdata fields with the prefix 'pre_user'. See description above.
  • Uses: do_action() Calls 'profile_update' hook when updating giving the user's ID
  • Uses: do_action() Calls 'user_register' hook when creating a new user giving the user's ID
The $userdata array can contain the following fields
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_pass
user_login A string that contains the user's username for logging in. pre_user_login
user_nicename A string that contains a URL-friendly name for the user. The default is the user's username. pre_user_nicename
user_url A string containing the user's URL for the user's web site. pre_user_url
user_email A string containing the user's email address. pre_user_email
display_name A string that will be shown on the site. Defaults to user's 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 user's nickname, defaults to the user's username. pre_user_nickname
first_name The user's first name. pre_user_first_name
last_name The user's 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 user's role. (none)
jabber User's Jabber account. (none)
aim User's AOL IM account. (none)
yim User's Yahoo IM account. (none)


When performing an update operation, user_pass should be the hashed password and not the plain text password.

Change Log

Since: 2.0.0

Source File

As of 3.1 wp_insert_user() is located in wp-includes/user.php.

Related

wp_update_user, wp_create_user

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