Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+9 votes
1.9k views
in Plugins by

Hello, I've tried to tweak the code so that the user's full names are displayed instead of their username. 

I want users to register using their email address, provide a password and their full names. 

The system should then append the user's full name (or display name) which is mandory during registeration instead of a username as it is right now. Having users register another "username" that they've to remember ontop of other usernames and email address they already have to me is sort of to much. 

 

Now, iv'e looked at the qa-app-format.php file and seen this function;

 

function qa_any_get_userids_handles($questions)
/*
Each element in $questions represents a question and optional associated answer, comment or edit, as retrieved from database.
Return an array of elements (userid,handle) for the appropriate user for each element.
*/
{
$userids_handles=array();
 
foreach ($questions as $question)
if (isset($question['opostid']))
$userids_handles[]=array(
'userid' => @$question['ouserid'],
'handle' => @$question['ohandle'],
);
 
else
$userids_handles[]=array(
'userid' => @$question['userid'],
'handle' => @$question['handle'],
//return user's full names instead of their handle instead, but what's the key for the @$question associated array?
//'handle' => @$question['name'],
//'handle' => "okwii david",
);
 
return $userids_handles;
}
 
So i've tried replacing something like @$question['name'] for @$question['handle'], but it seems there's no "name" key in the $question array. 
 
So what file/function should i tweak. What should i do? Thanks in advance 

 

Q2A version: 1.5.3
by
have you found a resolution to this?  I'm usign a custom single-sign-on solution that keeps the user table (ie, not using the external authentication module) but I'd like to display the user's name instead of their user id everywhere.
by
Although I realized that at certain site, it is not easy. Since I changed many core programs(Various pages, Various plugin, Email notification, ... etc), it is difficult to explain all here.

1 Answer

+4 votes
by
edited by

Although I cannot write all, I show fragmentary-hack-example. There is also method of overriding of  function. The reconstruction which it is at the user's registration and forces the input of "name" field is independently required by filter plugin. 

Source: qa-include/qa-app-users.php
Function: qa_get_one_user_html()

function qa_get_one_user_html($handle, $microformats) {

  if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
 
  // replace [start]
  //return strlen($handle) ? ('<A HREF="'.qa_path_html('user/'.$handle).
  // '" CLASS="qa-user-link'.($microformats ? ' url nickname' : '').'">'.qa_html($handle).'</A>') : '';
  if(strlen($handle) != 0) {
    $userprofiles = qa_db_select_with_pending(qa_db_user_profile_selectspec($handle,false));
    if(@$userprofiles['name'] != '')
      return '<A HREF="'.qa_path_html('user/'.$handle).'" CLASS="qa-user-link'.($microformats ? ' url nickname' : '').'">'.qa_html($userprofiles['name']).'</A>';
    else
      return '<A HREF="'.qa_path_html('user/'.$handle).'" CLASS="qa-user-link'.($microformats ? ' url nickname' : '').'">'.qa_html($handle).'</A>';
  } else {
    return '';
  }
  // replace [end]
}
 
I want this code to be helpful to someone. 
 
by
Thanks ScottCher for your follow.
by
This code change conflicts with the Q2A Badges plugin from NoahY because it modifies what that plugin looks for in order to display the badge widgets.  I've modified NoahY's code locally to address this but keep that in mind if.
by
sama55 - Thank you so much for sharing. SchottCher - This is such an important part of the function of a successful professional QA site. Could you briefly share what you modified in badges? I couldn't find where the function is pulled although I did see an include for the php file.

I'll also have to take a look at modifying the user profile page, which uses the user's user name as the title. Full Name is revealed within the user profile.
by
Good work around. Thanks.

Just to note: The code below is already enough and equavelent to the one you've given. Adding is better than replacing. Maybe one could make a simple plugin to avoid untrackable conflicts and a lot of uncontrolled implementations in the main code structure.

--

function qa_get_one_user_html($handle, $microformats) {

  if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }

  // add [start]
  if(strlen($handle) != 0) {
    $userprofiles = qa_db_select_with_pending(qa_db_user_profile_selectspec($handle,false));
    if(@$userprofiles['name'] != '')
      return '<A HREF="'.qa_path_html('user/'.$handle).'" CLASS="qa-user-link'.($microformats ? ' url nickname' : '').'">'.qa_html($userprofiles['name']).'</A>';
  }
  // add [end]

  return strlen($handle) ? ('<A HREF="'.qa_path_html('user/'.$handle).
   '" CLASS="qa-user-link'.($microformats ? ' url nickname' : '').'">'.qa_html($handle).'</A>') : '';
}

--
...