Different fields in My Profile page depending on user role

So I understand that I can user current_user_can to check the role of the current logged in user. But what I would like to do is show these different fields to the site Admin.

So for example the contributor role may have different custom fields than the subscriber. Each role would see their relative fields but the Admin would see a whole list of all fields in a contributor profile page and subscriber profile page.

Read More

Is there a way to allow the admin to only see certain fields of a user profile page?

I hope this makes sense to you out there!

Thanks in advance.

Related posts

Leave a Reply

1 comment

  1. I’ll post whole code which have to be in functions.php it’s legit WP valid code, how it should be done 🙂
    This should work, of course you have to put your role name in switch.

    UPDATED FOR PERFORMANCE:

    add_action( 'show_user_profile', 'user_fields_for_admin', 10);

    add_action( 'edit_user_profile', 'user_fields_for_admin', 10);

    function user_fields_for_admin( $user ){
    
     switch ($user->roles[0]) {
      case 'SOME ROLE':
        echo '<b>This is the role specific fields</b>';
        echo 'fields....';
        break;
      case 'SOME ANOTHER ROLE':
        echo '<b>This is the role specific fields</b>';
        echo 'fields....';
        break;
    
     }
    
     }