Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
488 views
in Themes by

Hello, How can I show different color for different user types on user profile?

For example, i want to show red color font for admin and green color for others.

Like this: Admin and Editor

1 Answer

+2 votes
by
selected by
 
Best answer

1. Create new layer plugin.

class qa_html_theme_layer extends qa_html_theme_base {
    public function main_part($key, $part) {
        if ($key == 'form_profile'
        && isset($this->content['raw']['account']['level'])
        && isset($part['fields']['level']['value'])) {
            $value = &$part['fields']['level']['value'];
            $value = '<span class="qa-custom-user-level qa-custom-user-level-'.$this->content['raw']['account']['level'].'">'.$value.'</span>';
        }
        qa_html_theme_base::main_part($key, $part);
    }
}

2. Add custom style in "Admin" > "Layout" > "Custom HTML in <head> section of every page:"

For example...

<style>
.qa-custom-user-level {
font-weight:bold;
}
.qa-custom-user-level-100,
.qa-custom-user-level-120 {
color:red;
}
...
</style>

3. Additional information:

Refer qa-include/app/users.php about user level constant. 

    define('QA_USER_LEVEL_BASIC', 0);
    define('QA_USER_LEVEL_APPROVED', 10);
    define('QA_USER_LEVEL_EXPERT', 20);
    define('QA_USER_LEVEL_EDITOR', 50);
    define('QA_USER_LEVEL_MODERATOR', 80);
    define('QA_USER_LEVEL_ADMIN', 100);
    define('QA_USER_LEVEL_SUPER', 120);

by
edited by
When you apply this changes to the whole system, upper logic is not suitable. It would be better to hack the core. However, it is necessary to apply these changes again when the core is upgraded.

Hacks:

1. Add below function in to the qa-include/app/users.php

function qa_user_level_html($level) {
    return '<span class="qa-user-level qa-user-level-'.$level.'">'.qa_user_level_string($level).'</span>';
}

2. Grep(Search) under qa-include with "qa_user_level_string" string.
3. Replace from "qa_html(qa_user_level_string(...))" to "qa_user_level_html(...)".

Core developers might merge these changes into the core.
by
Thanks for your info. And i have last one question. how can I color to username?
by
Normally, the link of the user (handle) name has the class "qa-user-link". You can override theme style in "Admin" > "Layout" > "Custom HTML in <head> section of every page:"

For example:
.qa-user-link:link { color: #0000ff; }
.qa-user-link:visited { color: #000080; }
.qa-user-link:hover { color: #ff0000; }
.qa-user-link:active { color: #ff8000; }

Unfortunately, we can not color user names considering user level. In that case you will need to further hack the core.
...