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 would like new users of the blog to have custom role, rather then Subscriber. How do I set this programmatically? I know that it can be changed from the backend.

share|improve this question
up vote 4 down vote accepted

This allows plugins to easily hijack the default role while they're active.

// Hijack the option, the role will follow!
add_filter('pre_option_default_role', function($default_role){
    // You can also add conditional tags here and return whatever
    return 'subscriber'; // This is changed
    return $default_role; // This allows default

I use it to make sure some plugins that need subscriber roles get it regardless of Administrator attempts to change :)


share|improve this answer

When a new user is created through the wp_insert_user() function, the role is set with the set_role() method of the User class and is set to the default user role.

The default user role is retrieved from the database get_option('default_role') and can be set via the Admin Dashboard by going to Settings > General > New User Default Role.

If you've registered your new role (using add_role(), it should be available there to choose from.

Alternatively, for more control you can hook into the user_register or profile_update actions to then set_role on them conditionally, or however else you like.

share|improve this answer
I will mark your one as correct, although real answer turned out to be as simple as update_option('default_role', 'custom_role_name') upon activation of the plugin. – jayarjo Oct 22 '11 at 9:05
Glad to have been of help. – soulseekah Oct 22 '11 at 9:09

After you created the user using

$user_id = wp_create_user( $user_login, $pas1, $user_email );

Create the user object

$user = new WP_User($user_id);

Then set the role


You can replace the 'editor' role with any of the following:

  • Administrator

  • Editor

  • Author

  • Contributor

  • Subscriber

share|improve this answer

Put it into the Pluging or functions.php of your theme

//Make 'Client' a default role

share|improve this answer
Why?? It serves no purpose to put your code somewhere without knowing what it does or how it works – Pieter Goosen Sep 16 '15 at 19:58

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.