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
1 Answer
Reset to default 0Well, 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.