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 |
#52
|
|||
|
|||
It's working Great! Thanks for your help.
-Paul |
#53
|
|||
|
|||
Quote:
|
#54
|
|||
|
|||
Ah yes... Sorry.
She said that the variables were different after email activation (in the script... I think). Thats all I know :-) But the script is now doing everything we need on our site. Thanks, Paul Fletcher |
#55
|
||||
|
||||
This plug is awesome.
I would like to use it to have a radio-button single selection going on where users can switch as the please. How would I go about accomplishing that? Just a bunch of if statements checking which groupid needs to be removed before assigning a new one? |
#56
|
|||
|
|||
Are you talking about adding the radio-buttons in the user CP, so a user is able to switch between categories and user-groups as they want?
Thanks, Paul |
#57
|
||||
|
||||
Yes that is exactly it. The user will have the choice between usergroupA, usergroupB, and usergroupC. The choice is made using radio buttons, so the user can only be a member of one of the groups at any given time. But the user can switch groups at will through the Edit Profile.
|
#58
|
|||
|
|||
I actually looked into doing something like that. Where our activation code text field would be able to be changed in the login / privacy area. Although for this to work you would have to change the hook. Probably from register_activate_process to when you login.
Although I don't know how to do this (modifying the original script), you could just try playing around with the hook settings. So every-time the user logs in, the script is activated to see what the value of that radio button is. Thanks, Paul |
#59
|
|||
|
|||
Quote:
Anyone happen to have this installed on a board that they could let me look at? |
#60
|
||||
|
||||
The choice doesn't have to be radio buttons. A text field works as well. But, the choice can't be changed after the user registers. They would have to use the regular member group interface for that.
|
#61
|
|||
|
|||
Quote:
When you say, "They would have to use the regular member group interface for that." "They" are Admins, not members, right? |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|