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 |
#92
|
||||
|
||||
Does anyone know if this will work for 3.6?
Woot for 200 posts |
#93
|
|||
|
|||
I was wanting it for 3.6 as well, any ideas anyone?
|
#94
|
||||
|
||||
amykhar said that she has it working, so it should probly work.
|
#95
|
||||
|
||||
It would be nice to be able to allow multiple instances of this running for different user groups based on different values.
|
#96
|
|||
|
|||
Not sure what i'm doing wrong, here is the code i'm using, it is field5 that i'm wanting, and 'Female' is what i'm looking for, to put into group 33, if they aren't Female, then group 2. What have i done wrong?
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'] == 'Female')
{
$membergroupids = $userdata->fetch_field('membergroupids');
if ($membergroupids)
{
$membergroupids = $membergroupids . ", 33";
}
else
{
$membergroupids = 2;
}
$userdata->set('membergroupids', $membergroupids); }]]></phpcode>
</plugin>
</plugins>
|
#97
|
||||
|
||||
Quote:
Code:
{ $membergroupids = 2; } Code:
{ $membergroupids = 33; } |
#98
|
|||
|
|||
How do I update the currently registered users for this? Where to I place the hook?
I'm using it as a gender mod. |
#99
|
||||
|
||||
Good question: Here's what I did:
I made the new Profile Field for this mod as 'Private', which means once it is entered, the field doesn't show up to be editted by the user or shown. However, the problem lies in the existing users. What you do is run a SQL Statement to update the value of that field for all users to, say, 'none'. This script only works for new registrations ongoing. If a user adjusted the value of that field, it won't add them to your secondary group unless it was while they were registering. You should make the default value 'none' & instruct your visitors to only fill in their 'Invitation Code' if they were given one. |
#100
|
|||
|
|||
I'm having a problem with this nice hack.
When NEW members on my forum register and choose from the custom-field (male or woman) they won't see at all the special corners that are made for male/woman members. This hack does work with existing members. Who could help me with this. At the begin it worked fine, but now it seems their is a strange problem with it, i self think that it's at the hook location. I would be thankfull. Medina |
#101
|
|||
|
|||
Quote:
Quote:
I have about 10 usergroups.. I would like to let users join one more (even all). |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|