Make WordPress Core

Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#9891 closed defect (bug) (fixed)

wp_insert_user() ignores 'role' when creating user

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

Description

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);
$user->set_role($role);

}

if ( !$update ) {

$user = new WP_User($user_id);
$user->set_role(get_option('default_role'));

}

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 17 years ago.

Download all attachments as: .zip

Change History (4)

#1 @Denis-de-Bernardy
17 years ago

  • Milestone Unassigned → 2.8
  • Status new → accepted

#2 @Denis-de-Bernardy
17 years ago

  • Keywords has-patch added

please give the attached patch a shot

#3 @westi
17 years ago

  • Resolution → fixed
  • Status accepted → 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.