WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making a plugin that creates user accounts. Is there a way I can create new users that get the role that I (the plugin developer) tell them to, as opposed to making them all the default new user role. I want to make new users a role type that is defined by my plugins parent plugin.

share|improve this question
up vote 0 down vote accepted

You can use the user_registration action to set a custom role directly after wp_insert_user() has been called.

add_action('user_register', 'foo_set_new_user_role', 9999, 1);
function foo_set_new_user_role($user_id){
    $user = new WP_User( $user_id );

You can also use the action profile_update for just that, profile updates. It takes two parameters $user_id and $old_user_data.

Hope this helps you out.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.