Different fields in My Profile page depending on user role

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;

 }

 } 

Leave a Comment