Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
677 views
in Q2A Core by
I want to show the full name of user in all post meta like question, answer, comment, private message etc.

Please help me to do this.
Q2A version: Latest
by
edited by
It's more complicated than a few lines of code. Full names are stored in qa_userprofile table, so you need an extra step to get the information there.

The best way is to create an Override Plugin that overrides the function qa_get_one_user_html  like this plugin https://github.com/scottcher/q2a-userid-display-override

Not really sure if it still works til this day.

Alternately, you can override public function post_meta_who($post, $class) in your theme with the same logic: you do an extra MySQL request on qa_userprofile table to get the required column value (here in this case, it is "name").

Check out a sophisticated plugin that manipulates user profiles:
https://github.com/yshiga/q2a-user-profile

The first method may avoid conflicts as many plugins and themes are more likely to manipulate post_meta functions.
by
Try my fixed version of the old plugin: https://github.com/q2aprick/q2a-full-name
by
edited by
Thanks for your answer, I have replaced plugin codes with q2a original function.
by
@Won't Answer Pricks

Can you give me the modified post_meta_who($post, $class) function codes for showing full name.
by
edited by
I hope you already know that saving changes directly to core will not survive future upgrades. And your customized theme should be renamed as a different name (and in a different theme folder).

If you want to modify  post_meta_who function or its parent or grandparent functions, you are repeating what should be done with qa_get_one_user_html.

The code is long, and I'm not sure if it's syntacially correct. In my site, I use a custom function for this, so cannot actually test.

public function post_meta_who($post, $class)
    {
        if (isset($post['who'])) {
            $this->output('<span class="' . $class . '-who">');

            if (strlen(@$post['who']['prefix']))
                $this->output('<span class="' . $class . '-who-pad">' . $post['who']['prefix'] . '</span>');

//change to fullname if exists
            if (isset($post['who']['data'])){
$handle = $post['raw']['handle'];
$userprofiles = qa_db_select_with_pending(qa_db_user_profile_selectspec($handle,false));
if (isset($userprofiles['name'])){
$fullname = qa_html($userprofiles['name']);
$this->output('<span class="' . $class . '-who-data"><span itemprop="author" itemscope itemtype="https://schema.org/Person"><a href="../user/'.qa_html($handle).'" class="qa-user-link" itemprop="url"><span itemprop="name">'.$fullname.'</span></a></span></span></span>');
}

else {
$this->output('<span class="' . $class . '-who-data">' . $post['who']['data'] . '</span>');
}
}

//end of change to fullname
            if (isset($post['who']['title']))
                $this->output('<span class="' . $class . '-who-title">' . $post['who']['title'] . '</span>');

            // You can also use $post['level'] to get the author's privilege level (as a string)

            if (isset($post['who']['points'])) {
                $post['who']['points']['prefix'] = '(' . $post['who']['points']['prefix'];
                $post['who']['points']['suffix'] .= ')';
                $this->output_split($post['who']['points'], $class . '-who-points');
            }

            if (strlen(@$post['who']['suffix']))
                $this->output('<span class="' . $class . '-who-pad">' . $post['who']['suffix'] . '</span>');

            $this->output('</span>');
        }
    }
by
edited by
I think it can be better with direct MySQL query with userid


$userid = $post['raw']['userid'];
$userprofiles = qa_db_read_one_value(qa_db_query_sub('SELECT content FROM ^userprofile WHERE userid=$ and title ="name"', $userid),true);

Please log in or register to answer this question.

...