vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.5 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=113)
-   -   Add User to Primary Usergroup Based on Value of Custom Profile Field (https://vborg.vbsupport.ru/showthread.php?t=82992)

amykhar 06-12-2005 10:00 PM

Add User to Primary Usergroup Based on Value of Custom Profile Field
 
This version is for the PRIMARY group. Here is the one for secondary groups:

https://vborg.vbsupport.ru/showthread.php?t=82993

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 primary user group based on that selection. This happens at the time the user activates their email account after registering.

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 User Group Based on 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')
                {
                        $userdata->set('usergroupid', 10);
                }]]></phpcode>
        </plugin>
</plugins>

If, for example, you want to check the value of field6, change field5 in the XML file to field6. If you are looking for "male" instead of "yes", change
Code:

if ($user['field5'] == 'yes')
to:

Code:

if ($user['field5'] == 'male')
And, finally, change the usergroup as appropriate. Instead of 10 in this line:
Code:

$userdata->set('usergroupid', 10);
substiture your usergroupid of choice.

Option 2: Import the XML file as is, open the plugin manager, and make your edits there.


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.

Amy

Brinnie 07-15-2005 04:22 AM

Hello, I cannot seem to find the alternate "female" option in your code examples.

How does one go about adding that?

Brinnie 07-15-2005 04:58 AM

Hello, I just installed it and and it didn't work! :(

I registered a test account and chose the option "male" as directed in the in instructions, but it stayed in the same group :(

I uploaded this XML:
Quote:

<?xml version="1.0" encoding="ISO-8859-1"?>

<plugins>
<plugin active="1" product="vbulletin">
<title>Put User In User Group Based on 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'] == 'male')
{
$userdata->set('usergroupid', 12);
}]]></phpcode>
</plugin>
</plugins>
Does it make a difference if I use radio buttons?
Please help :(

Brinnie 07-15-2005 06:20 AM

please help. :(

Brad 07-15-2005 09:28 AM

There is no need to bump a thread so many times in such a short time peroid.

Did you create a new custom profile field via the admin cp?

http://www.vbulletin.com/docs/html/profile_introduction

Brinnie 07-15-2005 11:41 AM

Quote:

Originally Posted by Brad
There is no need to bump a thread so many times in such a short time peroid.

Did you create a new custom profile field via the admin cp?

http://www.vbulletin.com/docs/html/profile_introduction

Yes sir, I did. I used radio buttons. set one to male, set one to female and made it required on registration.

Anything else I could have missed?

amykhar 07-15-2005 12:36 PM

Make sure you have it case sensitive. Make sure you get the right field number and make sure you have the right user group number.

Brinnie 07-15-2005 07:57 PM

Quote:

Originally Posted by amykhar
Make sure you have it case sensitive. Make sure you get the right field number and make sure you have the right user group number.

yes, it's field number 5, my first custom field.
yes, case is correct.
and im quite sure usergroup 12 is the one I want them to be added to.
the customized usergroup1.xml I posted was exactely what I uploaded into the plugins.

I do not understand why it does not work. Might it be related to the idea that there is no secondary "female" option in your example script?

amykhar 07-15-2005 08:11 PM

Brinnie, you have to remember 3.5 is beta software. It's working on my test board and my live board. Nobody else has complained that it doesn't work. I don't know why it's not working for you.

And given that you've changed the copyright in your footer, I can't see what version of the beta you are using.
p.s. I'm not entirely certain that your copyright is kosher according to the vbulletin license.

Brinnie 07-16-2005 04:44 PM

Quote:

Originally Posted by amykhar
Brinnie, you have to remember 3.5 is beta software. It's working on my test board and my live board. Nobody else has complained that it doesn't work. I don't know why it's not working for you.

And given that you've changed the copyright in your footer, I can't see what version of the beta you are using.
p.s. I'm not entirely certain that your copyright is kosher according to the vbulletin license.

Amy,

it's a beta 4.
but, i don't want the words "beta" anywhere on my site, so I pwnd it.


All times are GMT. The time now is 11:07 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01193 seconds
  • Memory Usage 1,749KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete