0

Is it possible to add a new subscriber role with a function, that has the same capabilities with the existing subscriber role within Wordpress?

Basically I would like to distinguish between male and female subscribers based on the wordpress role.

  • Do you want to add a new role for each user, or create custom roles that you assign to user ? – Elex Jun 18 '18 at 13:58
  • I want to create a new role that I can assign to users. e.g. "Male Subscriber", "Female Subscriber" – Joanna Mikalai Jun 18 '18 at 14:48
  • What you're looking for is here ! codex.wordpress.org/Function_Reference/add_role :) – Elex Jun 18 '18 at 16:29
  • you could also do this with user meta – yobddigi Jun 18 '18 at 17:02
  • thanks but the explanation on the codex page is a bit confusing and talks about creating a custom plugin. I was wondering if there is an easier way with a function. – Joanna Mikalai Jun 18 '18 at 19:24
1

A subscriber has only 1 capability namely: read
To create a new (custom)role just add following code-lines in functions.php.

Please make back-up first and so on....

When added to functions.php go into the back-end and check if you can add an (new or existing) user to this role.
When all is working you can delete the code because the roles are now added to the database and there is no need to keep them.

/**
 * Create new custom role(s)
 * 
 * Subscriber capability set: read
 * 
 * Source {@link https://wordpress.stackexchange.com/q/306353/15605}
 * @see   {@link https://codex.wordpress.org/add_role}
 * @see   {@link https://codex.wordpress.org/Roles_and_Capabilities}
 *
 * @version  WordPress 4.9.6
 * 
 */
    // Adjust to your own preferences.
    // Subscr_F and M are visible in you back-end, but you can adjust all.
    add_role( 'subscr_female', __( 'Subscr_F' ), array( 'read' => true ) );
    add_role( 'subscr_male',   __( 'Subscr_M' ), array( 'read' => true ) );

I hope this is what you where looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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