Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

how to make username show only by admin

+2 votes
1,128 views
asked Jan 24, 2014 in Q2A Core by Lexoos
hello, 
 
 
 
nice code. i just see the username when they ask a question or make some modification. recategorize, comment, blog, ect...
 
my question is:
 
we can show the username or nickname only for the admin or moderator and hide every where when they make any action ? 
 
i would like only the admin or moderator can see there username. 
 
Cordially Marc
 
Q2A version: 1.6.3
related to an answer for: Hide user/nickname in core

1 Answer

+1 vote
answered Jan 25, 2014 by jatin.soni
edited Jan 25, 2014 by jatin.soni

If you want to show to only Admin and above (super admin) than only need to change QA_USER_LEVEL_MODERATOR to QA_USER_LEVEL_ADMIN

See my updated code on Gist here https://gist.github.com/q2amarket/8405467

function post_meta_who($post, $class)
{ 
    $type = $post['raw']['type'];
    $level = qa_get_logged_in_level();
    $type_array = array('Q_QUEUED', 'A_QUEUED', 'C_QUEUED');
     
    if($this->template == 'question' || (in_array($type, $type_array) && $level >= QA_USER_LEVEL_ADMIN))
    qa_html_theme_base::post_meta_who($post, $class);
}

Edit: New code based on your comment and fixed error on PM page

Find on Gist https://gist.github.com/q2amarket/8405467

// to hide who meta from everyone except admin and above
// from everywhere Question, Answer, Comment etc..
// in all mode, moderation and published
function post_meta_who($post, $class)
{

    $type = @$post['raw']['type']; // remove this line too, you don't need it
    $level  = qa_get_logged_in_level();

    if(qa_is_logged_in() && $level >= QA_USER_LEVEL_ADMIN)
        qa_html_theme_base::post_meta_who($post, $class);
}

 

Info

1. By adding @ before $post will fix the error on PM page, (see the code)

2. Since you need everywhere than I don't think you need to check for moderation queue. Just cross check once with that eithe rit is working without adding $type_array in condition or not. If it won't work than add Q, A, C in array as well like below

$type_array = array('Q_QUEUED', 'A_QUEUED', 'C_QUEUED', 'Q', 'A', 'C');

3. I have added qa_is_logged_in() (which I forgot to add in previous code) to perform check and show who meta to only logged in user than further condition

Hope this will solve your issue


Ah! than now you don't need $type as well. Just remove entire line $type = @$post['raw']['type'];

commented Jan 28, 2014 by Claude
Thank you so much Jatin, you are the Best !!! This is works.
commented Jan 28, 2014 by jatin.soni
Glad to help you. :))
...