Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#9891 closed defect (bug) (fixed)

wp_insert_user() ignores 'role' when creating user

Reported by: jammin23 Owned by: Denis-de-Bernardy
Milestone: 2.8 Priority: normal
Severity: normal Version:
Component: Role/Capability Keywords: has-patch wp_insert_user, role, registration, account creation
Focuses: Cc:


In Wordpress 2.7.1 and possibly other versions, the documentation for wp_insert_user() claims that it accepts 'role' in the $userData array. This is not true when creating a user, only when updating an existing account.

wp-includes/registration.php starting line 202:

if ( $update && isset($role) ) {

$user = new WP_User($user_id);


if ( !$update ) {

$user = new WP_User($user_id);


If the user is being created, the role is always set to the default role, not the one that was specified by the API call.

This probably makes no odds at all within Wordpress, but I'm using a plugin (Simple LDAP Login) which needs to set role on account creation. A workaround of course is to set the role with wp_update_user() after creating the account, but this shouldn't be necessary according to the function's documentation.

Attachments (1)

9891.diff (593 bytes) - added by Denis-de-Bernardy 7 years ago.

Download all attachments as: .zip

Change History (4)

#1 @Denis-de-Bernardy
7 years ago

  • Milestone changed from Unassigned to 2.8
  • Status changed from new to accepted

#2 @Denis-de-Bernardy
7 years ago

  • Keywords has-patch added

please give the attached patch a shot

#3 @westi
7 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [11442]) Allow a different role to be set for users when they are created in a call to wp_insert_user(). Fixes #9891 props Denis-de-Bernardy.

Note: See TracTickets for help on using tickets.