Is it possible to do this? I already know about get current_user_can(), which does not work like I need. I’d like to be able to use an array if there are multiple roles.
// Check roles to only add fields to necessary users
function check_role( $user ) {
$user_role = get_user_role($user->ID);
if($user_role == 'author') {
return true;
} else {
return false;
}
}
add_action('show_user_profile', 'check_role');
add_action('edit_user_profile', 'check_role');
if(check_role()) {
add_action('show_user_profile', 'add_user_fields');
add_action('edit_user_profile', 'add_user_fields');
add_action( 'personal_options_update', 'save_user_fields' );
add_action( 'edit_user_profile_update', 'save_user_fields' );
}
On the profile page exists a global variable
$profileuser
. The member$profileuser->roles
is an array of all roles for that user.Output:
Use this list to compare the roles.