0

I added a new user role by add_role() function via my plugin's activation function. I would like to add an integer parameter to such custom role, for example, score parameter which the default value is 100.

How can I achieve adding such parameter?

  • Please read this post cloudways.com/blog/add-custom-user-roles-in-wordpress – Gufran Hasan Oct 4 '19 at 7:59
  • @GufranHasan the article does not mention anything about adding custom parameter. – Raptor Oct 4 '19 at 8:03
  • 1
    The WP_Role/WP_Roles class doesn't currently support custom data, but you can use something like add_option( 'role_name_score', 100 ) or add_option( 'role_name_data', array( 'score' => 100, ... ) ). – Sally CJ Oct 4 '19 at 9:42
  • @SallyCJ this is a nice idea. – Raptor Oct 8 '19 at 2:13
  • 1
    Well, I thought you meant the role itself (e.g. editor) and not a user of that role.. :) And for user-specific, how about using a custom meta/field - e.g. add_user_meta( 123, 'score', 100 ) (or maybe save an array of data) ? But you can still use the add/update_option to set the default score/value for all users of that role.. – Sally CJ Oct 8 '19 at 16:05

Your Answer

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

Browse other questions tagged or ask your own question.