• Resolved aptharsia

    (@aptharsia)


    I’ve tried various things but the user role will not display. I want it to show under the user meta. I’ve used the example on the hooks page with additional code to display that particular users role. But it will not display the user role.

    // add user role to profile page header under meta
    add_action( 'um_after_header_meta', 'my_after_header_meta', 10, 2 );
    function my_after_header_meta( $user_id, $args ) {
      
    	$comment_id = get_comment_ID();
    $user_id = get_comment( $comment_id )->user_id;
    	$user = new WP_User( $user_id );
    	$user_roles = $user->roles;
        $user_role = array_shift($user_roles);
    
        if ($user_role == 'administrator') {
            echo '<div class="">Admin</div><br>';
        } elseif ($user_id == '1') {
            echo '<div class="">Moderator</div><br>';
        } elseif ($user_id == '2') {
            echo '<div class="">Admin</div><br>';
        } elseif ($user_role == 'contributor') {
            echo '<div class="">Supporter</div><br>';
        } elseif ($user_role == 'supporter') {
            echo '<div class="">Supporter</div><br>';
    	} else {
            echo ' ';
        }
    	
    }

    I’m also just tried
    echo um_user('role_name');
    as the function (as in replaced the long code within the function with the simpler code.) I know the function works for plain text but not for getting and display the user role.

    Has anyone else been able to display the user role anywhere on the profile pages?

The topic ‘adding user role to user meta’ is closed to new replies.