Support » How-To and Troubleshooting » wp_insert_user function User Roles

wp_insert_user function User Roles

  • Hi i am using the wp_insert_user function

    wp_insert_user( array ('ID' => $user_id,
    					   'user_url' => $website,
    					   'user_login' => $user_name,
    					   'user_pass' => $random_password,
    					   'user_email' => 'example@hotmail.co.uk',
    					   'user_login' => $user_name,
    					   'first_name' => 'Samuel',
    					   'last_name' => 'East',
    					   'role' => 'Administrator'
    					   ) ) ;

    everything works great apart from ‘role’ => ‘Administrator’ when i set it to this it says none.

    In the codex it says
    role A string used to set the users role.

    Can anyone explain why this doesnt work i have tried user levels???

Viewing 2 replies - 1 through 2 (of 2 total)
  • This function has been working for me until yesterday. This looks like a bug and not sure if it’s related to updates in 3.1.3 – 3.2 but assigning a role using ‘Contributor’ or ‘contributor’ as well as not defining the role and relying instead upon the default role setting results in a “none” being assigned to the role.

    Thoughts anyone?

    actually not a bug. it looks like sanitize_meta() has been updated to be more specific and that caused an issue with insertion of the role as part of an array of data.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_insert_user function User Roles’ is closed to new replies.