Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
613 views
in Q2A Core by

Hello , how to test if a user is expert or more ? 

I want to add a verified badge if the user is expert or more and I'm looking at this function now: 

function qa_get_one_user_html($handle, $microformats=false, $favorited=false){

....

return '<a href="'.$url.'" class="qa-user-link'.$favclass.$mfclass.'">'.qa_html($handle).'</a>';

}

Q2A version: 1.7.4

1 Answer

+2 votes
by
selected by
 
Best answer

You could do something like this before the return:

// For qa_db_select_with_pending, qa_db_user_account_selectspec 
require_once QA_INCLUDE_DIR . 'db/selects.php'; 
 
$account = qa_db_select_with_pending(qa_db_user_account_selectspec($handle, false)); 
 
if (isset($account) && $account['level'] >= QA_USER_LEVEL_EXPERT) { 
    $handle .= ' (expert+)'; 
}

The appended text is just for a quick and visual reference. You should add whatever HTML you need.

by
Thanks for your answer !
Is this optimized ?
by
That is how you test if a given user (actually, a given handle) is expert+. Obviously, if you already had the account data already populated then you wouldn't need to fetch it again. Based on your example, you don't
by
It would be better that I have this data fetched, I will work on it.
Thanks again
...