Function: wp_insert_user

wp_insert_user( array | object | WP_User $userdata )

Insert a user into the database.

Most of the $userdata array fields have filters associated with the values. Exceptions are 'ID', 'rich_editing', 'syntax_highlighting', 'comment_shortcuts', 'admin_color', 'use_ssl', 'user_registered', and 'role'. The filters have the prefix 'pre_user_' followed by the field name. An example using 'description' would have the filter called, 'pre_user_description' that can be hooked into.

Parameters

Name Type(s) Default Value Description
$userdata array | object | WP_User

{ An array, object, or WP_User object of user data arguments.

@type int         $ID                   User ID. If supplied, the user will be updated.
@type string      $user_pass            The plain-text user password.
@type string      $user_login           The user's login username.
@type string      $user_nicename        The URL-friendly user name.
@type string      $user_url             The user URL.
@type string      $user_email           The user email address.
@type string      $display_name         The user's display name.
                                        Default is the user's username.
@type string      $nickname             The user's nickname.
                                        Default is the user's username.
@type string      $first_name           The user's first name. For new users, will be used
                                        to build the first part of the user's display name
                                        if `$display_name` is not specified.
@type string      $last_name            The user's last name. For new users, will be used
                                        to build the second part of the user's display name
                                        if `$display_name` is not specified.
@type string      $description          The user's biographical description.
@type string|bool $rich_editing         Whether to enable the rich-editor for the user.
                                        False if not empty.
@type string|bool $syntax_highlighting  Whether to enable the rich code editor for the user.
                                        False if not empty.
@type string|bool $comment_shortcuts    Whether to enable comment moderation keyboard
                                        shortcuts for the user. Default false.
@type string      $admin_color          Admin color scheme for the user. Default 'fresh'.
@type bool        $use_ssl              Whether the user should always access the admin over
                                        https. Default false.
@type string      $user_registered      Date the user registered. Format is 'Y-m-d H:i:s'.
@type string|bool $show_admin_bar_front Whether to display the Admin Bar for the user on the
                                        site's front end. Default true.
@type string      $role                 User's role.
@type string      $locale               User's locale. Default empty.

}

Returns

integer | WP_Error

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

WordPress Developer Newsletter

Stay on top of the latest WordPress API changes, developer tool updates, security alerts and more.