PDA

View Full Version : Change username color with a profile field


Bioman2k
09-23-2012, 10:16 AM
Hi,

I've made a World of Warcraft board for my guild.
Yesterday, I added new custom profile fields like player's name, player's class, player's server...

I would like to know if it's possible to attribute specific color to members when then correctly choose their class.

For example, if I register to my board and choose "mage", automatically, my name in every forums will be colored in #558A84.

To do that, I added the following CSS into additionnal.css file :


/* WoW Color Class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
.chaman {
color:#0070DE;
font-weight:bold;
}

.hunter {
color:#ABD473;
font-weight:bold;
}

.warlock {
color:#9482C9;
font-weight:bold;
}

.hunter {
color:#ABD473;
font-weight:bold;
}

.dk {
color:#C41F3B;
font-weight:bold;
}

.druid {
color:#ff7d0a;
font-weight:bold;
}

.warrior {
color:#c79c69;
font-weight:bold;
}

.mage {
color:#69CCF0;
font-weight:bold;
}

.monk {
color:#558A84;
font-weight:bold;
}

.paladin {
color:#f58cba;
font-weight:bold;
}

.priest {
color:#000000;
font-weight:bold;
}

.rogue {
color:#fff468;
font-weight:bold;
}


Any idea to do that ?
Thank you all in advance.

Bioman2k
09-26-2012, 12:23 PM
No Idea ?

Bioman2k
09-28-2012, 12:29 PM
Ok, I'd added usergroups like mage, DK, paladin and put a color CSS on them.

My question :
Is it possible to make a scheduled task (as CRON) which scan everyday for all members their profile field value and assign them onto the good usergroup.

I hope i was understandable.

Have a nice day.

kh99
09-28-2012, 12:54 PM
To answer your original question, you can make a plugin using hook fetch_musername that sets $user['musername'] (the formatted username) to whatever you want. But one issue is that you aren't guaranteed to have the user's custom fields available so you would have to do a database query to get any that you wanted to check. And since this is called to format posts, it could be called more than once for each user, so you'd probably want some kind of caching of fields to cut down on the number of queries.

To answer the above quesiton, you could do that. Hook cron_script_cleanup_hourly is called in the hourly cleanup script, so you could use that, or you could write your own scheduled task php script. You might want to look at includes/cron/promotion.php since it does something similar.

Another way to do what you're trying to do might be to find a hook that's called when the custom fields are edited, so you can detect a change in the field and reset the usergroups. One of the hooks in class_dm_user.php might work, like maybe userdata_presave (you'd have go to that file and look at the code around that hook to figure out exactly what to do).