MyBB Community Forums

Full Version: User sex?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm just wondering if anybody knows how to "detect" the user sex, and from there I'll try to make a Plugin/Setting for my Forum setting for normal women = Pink, normal men = Blue... ok thank you!
The only way to do this is if the user has set this in ther UserCP, which not many do unless you prompt them or give them reason to put it in. On my forums, women are often concerned about coming forward as its a male dominated sport/site.

The other method is if you enable facebook login and grab that data from there
Yeah but I mean, in code, for example a myBB Variable? like "{$uid}, {$memregdate}, {$memprofile['aim']}", that way i can manage to modify the PHP templates and make something like (hypothetical example):
IF ({$memprofile['sex']} == 'woman' || {$memprofile['sex']} == 1) {
{$memprofile['username'] = '<SPAN CLASS="group-woman">'.{$memprofile['username'].'</SPAN>';
}
ELSE IF ({$memprofile['sex']} == 'man' || {$memprofile['sex']} == 2) {
{$memprofile['username'] = '<SPAN CLASS="group-man">'.{$memprofile['username'].'</SPAN>';
}
ELSE {
{$memprofile['username'] = '<SPAN CLASS="group-normal">'.{$memprofile['username'].'</SPAN>';
}

And from there I would be able to change the color of the username, from the user sex.... meaning that it doesn't matter if the users put a sex or not....
If Woman = Username color is Pink
If Man = Username color is Blue
If Other or undefined = Username color is Gray

Setting by other way the respective CSS porperties for each "group-class".....
oh I see.

Its usually under $mybb->user

so in mine I don't have the gender, but say you had it as a custom userfield, actually it usually is a custom field

so your code would look something like


function genderbender()
{
    global $mybb;
    if($mybb->user["fid3"]=="Male")
    {
         echo "You are a man";
    }
}


To style these you need to play with the templates where you are displaying them as well. I am going to just leave the assumption you know how to edit templates from a plugin. If you don't take a quick look at a sample plugin and it should be fairly clear

NOTE: Apologies for the spacing in above code, I typed it into the text box so didn't have the option for tabs

Oh if you want to find out which field it is specifically just go to your ACP >> Configuration >> Custom Fields

hover over the "Sex" field and you should see the number in the URL (fid=x)

If you want to see a print out of all of the options that come out of the $mybb->user array just do a basic plugin with the following in it.



function mybb_arr_tst()	{
	global $mybb;
	echo "<pre>";
	print_r($mybb->user);
	echo "</pre>";
}


I do that and print out onto misc.php with all of the results every time I want to look it up different values. So in my dev environment I can feed in whatever I want from the screen and get these results. it really helps with development when you have sucha feature rich application like myBB
It depends where you want to check user's gender.
- globally for the current user only (also guests - always empty for them) it's {$mybb->user['fid3']} as Dannymh said
- in postbit templates for each poster it's {$post['fid3']}
- in member profile templates for each member it's {$memprofile['fid3']}
- in memberlist templates for each member it's {$user['fid3']}

Change 3 (default for Sex) to the custom profile ID.

In other places you will have to query the database to get the field.
Ok I think this is solved now, thank you ;3