Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
2.2k 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
Thank's Jatin

but i need to hide the username everywhere on the question, answer, comment, post, ect.. just the admin can see.

than i find a problem. if i send a private message to another user i get this error :

Notice: Undefined index: type in C:\AppServ\www\q2a\qa-theme\snow\qa-theme.php on line 28

maybe there :

 $type = $post['raw']['type'];
    $level = qa_get_logged_in_level();
    $type_array = array('Q_QUEUED', 'A_QUEUED', 'C_QUEUED');
by
hi Lexoos,

i have the same problem, just wait little ;) Jatin will find a solution
by
Find my edited answer. Let me know hows that..
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. :))
...