Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
2.1k views
in Q2A Core by
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
by
edited by

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'];

by
Hi jatin,

Thank you very much for this update, i already add this code to test

i will try tomorrow and i let you know ;)

Claude
by
Okay so replace the existing code and use this one... https://gist.github.com/q2amarket/8405467#file-q2am-hook-hide-meta-who1-2-mod-php instead. This method has both added and edited who meta (1 and 2)
by
Thank you so much Jatin, you are the Best !!! This is works.
by
Glad to help you. :))
...