Creating Custom user type just like custom post

admin2025-06-03  3

How to create custom user types (User Role) just like the custom post types.

For example:

User Role 1: Having a normal profile field. User Role 2: Having 3 extra fields in the profile.

2 different set of users with different user_meta fields.

How to create custom user types (User Role) just like the custom post types.

For example:

User Role 1: Having a normal profile field. User Role 2: Having 3 extra fields in the profile.

2 different set of users with different user_meta fields.

Share Improve this question edited Feb 19, 2019 at 14:17 Nidheesh Chandran asked Oct 30, 2013 at 13:47 Nidheesh ChandranNidheesh Chandran 32 bronze badges 1
  • Please improve your question, see How to Ask. Plugin recommendations are off topic, see On Topic. – Nicolai Grossherr Commented Oct 30, 2013 at 13:52
Add a comment  | 

1 Answer 1

Reset to default 0

Well, Roles are in many ways custom user types and you can add meta fields specific to roles. For example...

function is_my_user_role($id = null) {
  global $profileuser;
  if (empty($profile) && !empty($id)) $profileuser = get_user_to_edit($id);
  return (in_array('myrole',$profileuser->roles)) ? true : false;
}

function my_user_fields($profileuser) {
  if (!is_my_user_role()) return false;

  // HTML for the fields
}
add_action('show_user_profile', 'my_user_fields');
add_action('edit_user_profile', 'my_user_fields');

And essentially the same check when you go to save the data.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748889996a314571.html

最新回复(0)