I had a functionality requirement similiar to btappan's, but I needed the custom field to only be visible to those users who had permissions to view private custom fields.
To accomplish this, I modified KirbyDE's hack. I'm reposting Kirby's hack with my modifications (I hope this is proper procedure - this is the first time I've posted code) - thanks KirbyDE!!
The following steps will set up your Member List to display the Company Name (user field 5 in this example) as the first column and sort by it if the user has permissions to see private custom fields (assuming that user field 5 is a private custom field of course

), and display the default Member List if the user does not have permissions to see private custom fields.
In memberlist.php FIND
PHP Code:
// set defaults and sensible values
if ($sortfield == '')
{
$sortfield = 'username';
}
REPLACE that WITH
PHP Code:
// set defaults and sensible values
if ($sortfield == '')
{
if ($permissions['genericpermissions'] & CANSEEHIDDENCUSTOMFIELDS)
{
$sortfield = 'companyname';
}
else
{
$sortfield = 'username';
}
}
then FIND
PHP Code:
switch ($sortfield)
{
case 'username':
$sqlsort = 'user.username';
break;
BELOW that ADD
PHP Code:
case 'companyname':
$sqlsort = 'userfield.field5';
break;
Revert to the original versions of your memberlist and memberlist_resultsbit templates.
Set your Company Name field to NOT show up on members list
In template memberlist FIND
Code:
<td class="thead" align="$stylevar[left]" nowrap="nowrap"><a href="$sorturl&order=ASC&sort=username&pp=$perpage&ltr=$ ltr$usergrouplink">$vbphrase[username]</a> $sortarrow[username]</td>
ABOVE that ADD
Code:
<if condition="$permissions['genericpermissions'] & CANSEEHIDDENCUSTOMFIELDS">
<td class="thead" align="$stylevar[left]" nowrap="nowrap"><a href="$sorturl&order=ASC&sort=companyname&pp=$perpage&ltr=$ltr$usergrouplink">Company Name</a> $sortarrow[companyname]
</td></if>
In template memberlist_resultsbit FIND
Code:
<td class="alt1Active" align="$stylevar[left]" id="u$userinfo[userid]">
<a href="member.php?$session[sessionurl]u=$userinfo[userid]">$userinfo[musername]</a>
<if condition="$show['usertitlecol']"><div class="smallfont">$userinfo[usertitle]</div></if>
</td>
ABOVE that ADD
Code:
<if condition="$permissions['genericpermissions'] & CANSEEHIDDENCUSTOMFIELDS">
<td class="alt2Active" align="$stylevar[left]"> $userinfo[field5]
</td></if>
EDIT:
The following will allow the alpha search at the top of the memberlist page to sort by the added userfield.
In memberlist.php FIND
PHP Code:
if ($ltr != '')
{
if ($ltr == '#')
{
$condition = "username NOT REGEXP(\"^[a-zA-Z]\")";
}
else
{
$ltr = chr(intval(ord($ltr)));
$condition = 'username LIKE("' . addslashes_like($ltr) . '%")';
}
}
REPLACE that WITH
PHP Code:
if ($ltr != '')
{
if ($ltr == '#')
{
if (($sortfield == 'companyname') OR ($sortfield != 'username' AND ($permissions['genericpermissions'] & CANSEEHIDDENCUSTOMFIELDS)))
{
$condition = "field5 NOT REGEXP(\"^[a-zA-Z]\")";
}
else
{
$condition = "username NOT REGEXP(\"^[a-zA-Z]\")";
}
}
else
{
$ltr = chr(intval(ord($ltr)));
if (($sortfield == 'companyname') OR ($sortfield != 'username' AND ($permissions['genericpermissions'] & CANSEEHIDDENCUSTOMFIELDS)))
{
$condition = 'field5 LIKE("' . addslashes_like($ltr) . '%")';
}
else
{
$condition = 'username LIKE("' . addslashes_like($ltr) . '%")';
}
}
}