The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
Add User to Secondary Usergroup Based on the Value of a Custom Profile Field at Reg. Details »» | |||||||||||||||||||||||||||
Add User to Secondary Usergroup Based on the Value of a Custom Profile Field at Reg.
Developer Last Online: Nov 2013
This version is for the SECONDARY group. The one for primary groups is here:
https://vborg.vbsupport.ru/showthread.php?t=82992 As far as plugins goes, this one is an advanced plugin because you WILL need to make some tweaks to suit your needs. What this plugin does: If you have a custom profile field, for example one for gender, it checks to see if the user has selected a specific value and then assigns them to a secondary user group based on that selection. Instructions for installation: A. Create your custom profile field and make a note of the field number. (Or simply make a note of the field number of an existing field.) B. Make a note of the value you are checking for. For example, you may be looking to see if your member selected "male" in your custom gender field. C. Make a note of the usergroup number that you want to set the user to. D. Here you have two options: Option 1: Edit the attached XML file before you import it to change the field number, the value that you check for and the usergroupid. In my XML file, I am checking field5 to see if the value is yes and changing the usergroup to 10. Code:
<?xml version="1.0" encoding="ISO-8859-1"?> <plugins> <plugin active="1" product="vbulletin"> <title>Put User in Secondary Group Based on Custom Profile Field Value</title> <hookname>register_activate_process</hookname> <phpcode><![CDATA[// Get the value for field 5 $user = $db->query_first(" SELECT field5 FROM " . TABLE_PREFIX . "userfield WHERE userid = " . $vbulletin->userinfo['userid'] . " "); if ($user['field5'] == 'yes') { $membergroupids = $userdata->fetch_field('membergroupids'); if ($membergroupids) { $membergroupids = $membergroupids . ", 10"; } else { $membergroupids = 10; } $userdata->set('membergroupids', $membergroupids); }]]></phpcode> </plugin> </plugins> Example: if you are checking your field to see if the value is male, you would change (change field number as needed): Code:
if ($user['field5'] == 'yes') Code:
if ($user['field5'] == 'male') Code:
$membergroupids = $membergroupids . ", 10"; And in this line as well, Code:
$membergroupids = 10; NOTE: This mod works for forums that require users to verify their email address upon registration. If your forum does not require users to verify their email address, you will need to use a different hook. If I have time, I'll test that variation. ---------------- Example Gender Mod that separates users into secondary groups based on their gender. Don't forget, the values are case sensitive and the field numbers and usergroup numbers need to be changed to suit your site's setup. Code:
// Get the value for field 20 $gender = $vbulletin->db->query_first("SELECT * FROM userfield WHERE userid=".$vbulletin->userinfo['userid']); if ($gender['field20'] == 'male') { $membergroupids = $userdata->fetch_field('membergroupids'); if ($membergroupids) { $membergroupids = $membergroupids . ", 42"; } else { $membergroupids = 42; } $userdata->set('membergroupids', $membergroupids); } else { $membergroupids = $userdata->fetch_field('membergroupids'); if ($membergroupids) { $membergroupids = $membergroupids . ", 41"; } else { $membergroupids = 41; } $userdata->set('membergroupids',$membergroupids); } Show Your Support
|
Благодарность от: | ||
Insta-Gator |
Comments |
#62
|
||||
|
||||
No. I mean members. Members can leave public groups and ask to join public groups. Combine this with my mod that pms group leaders when users make a request, and you'll have a usable interface.
I don't need my members to change groups after registration becuase except in very rare cases, I don't think their gender is going to change |
#63
|
||||
|
||||
Quote:
I run an online game related message board, and users can have one of three allegiances. Depending on which allegiance they currently have, they are assigned to a usergroup that then assigns them a rank image that shows their allegiance. However, users can change their allegiance in game, and I would like them to be able to change their allegiance choice as well. I currently use simple publically joinable usergroups. The issue with that is that a user could join multiple groups and thus display multiple allegiance rank images. Some users do, and it's annoying to me to have to hunt them down and tell them that they are misusing the allegiance option. If I were able to make the allegiance choice a radio button choice in the profile, then they could only have one allegiance at a time, but they would need to be able to change it when they change it in game. There ought to be a faily simple way to do that. Something along the lines of: -radio button choice indicates user wants to be part of group A -check whether user is part of group B already, if so, remove user from group B -check whether user is part of group C already, if so, remove user from group C -add user to group A |
#64
|
||||
|
||||
a few months ago i was having trouble installing the "Put User in Secondary Group Based on Custom Profile Field Value" hack. Well i thought it was all sorted, but for some reason, users are still being put into any random fields(eg male or female). I have not edited any code or anything, but it has been an increasing issue (having to manually change users).
Has anyone got any thoughts? Please help |
#65
|
||||
|
||||
amykhar or even someone else...please help me out here
i have a gender field with 3 options (male,female,secret) how can i set males to have one secondary usergroup, for females another, and for those who selected ecret to remain as it is (dont get a secondary usergroup) |
#66
|
||||
|
||||
It's just ifs and elseifs to handle three groups.
|
#67
|
|||
|
|||
Is it possible to use this function based on two custom fields instead of one? If so, how would the code differ to the one above? Cheers.
|
#68
|
||||
|
||||
You'd just add another field to the plugin that looks for a different field.
Amy, here's my modified profile code, but it doesn't add me under a secondary usergroup. Any ideas? Code:
// Get the value for field 5 $user = $db->query_first(" SELECT field5 FROM " . TABLE_PREFIX . "userfield WHERE userid = " . $vbulletin->userinfo['userid'] . " "); if ($user['field5'] == 'North') { $membergroupids = $userdata->fetch_field('membergroupids'); if ($membergroupids) { $membergroupids = $membergroupids . ", 10"; } else { $membergroupids = 10; } $userdata->set('membergroupids', $membergroupids); } // Get the value for field 5 $user = $db->query_first(" SELECT field5 FROM " . TABLE_PREFIX . "userfield WHERE userid = " . $vbulletin->userinfo['userid'] . " "); if ($user['field5'] == 'South') { $membergroupids = $userdata->fetch_field('membergroupids'); if ($membergroupids) { $membergroupids = $membergroupids . ", 11"; } else { $membergroupids = 11; } $userdata->set('membergroupids', $membergroupids); } // Get the value for field 5 $user = $db->query_first(" SELECT field5 FROM " . TABLE_PREFIX . "userfield WHERE userid = " . $vbulletin->userinfo['userid'] . " "); if ($user['field5'] == 'West') { $membergroupids = $userdata->fetch_field('membergroupids'); if ($membergroupids) { $membergroupids = $membergroupids . ", 13"; } else { $membergroupids = 13; } $userdata->set('membergroupids', $membergroupids); } // Get the value for field 5 $user = $db->query_first(" SELECT field5 FROM " . TABLE_PREFIX . "userfield WHERE userid = " . $vbulletin->userinfo['userid'] . " "); if ($user['field5'] == 'East') { $membergroupids = $userdata->fetch_field('membergroupids'); if ($membergroupids) { $membergroupids = $membergroupids . ", 10"; } else { $membergroupids = 12; } $userdata->set('membergroupids', $membergroupids); } |
#69
|
||||
|
||||
ronoxQ, I'm going to respond via pm.
|
#70
|
|||
|
|||
I've got a 5-option radio field that I can't get to work corectly.
I sort of got it to work, but with this code, it it puts new members into 2 Groups, whatever they chose and always the last Group (the else clause) listed as well (so 2 groups). Where am I going wrong? PHP Code:
|
#71
|
|||
|
|||
Can I write this code? or use a switch statement
Code:
if ($user['field5'] == 'MIS (Summer)') { $membergroupids = $userdata->fetch_field('membergroupids'); if ($membergroupids) { $membergroupids = $membergroupids . ", 45"; } } if ($user['field5'] == 'MIS (Fall)') { $membergroupids = $userdata->fetch_field('membergroupids'); if ($membergroupids) { $membergroupids = $membergroupids . ", 45"; } } $userdata->set('membergroupids', $membergroupids); |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|