Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.5 > vBulletin 3.5 Add-ons
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Add User to Primary Usergroup Based on Value of Custom Profile Field Details »»
Add User to Primary Usergroup Based on Value of Custom Profile Field
Version: 1.00, by amykhar amykhar is offline
Developer Last Online: Nov 2013 Show Printable Version Email this Page

Version: 3.5.0 Beta 1 Rating:
Released: 06-12-2005 Last Update: Never Installs: 59
Uses Plugins
 
No support by the author.

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

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #82  
Old 10-30-2006, 02:42 AM
Oreamnos's Avatar
Oreamnos Oreamnos is offline
 
Join Date: Dec 2004
Posts: 130
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
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.
OK, after I registered about 20 new test users here is what i found regarding this plugin's use with non-email verification registrations.

I tried almost every register_hook_name and none of them worked. it doesn't seem like it's possible to process this plugin without using the email verification function.

That being said, if you only want to move a user to another primary group on registration without a custom field being checked, you can still do this:

Add this:
PHP Code:
$userdata->set('usergroupid'11); 
(where 11 is the ID of the new primary usergroup)

Hook that with:
register_addmember_process

Activate and every member that registers on your site will have their primary group changed to ID: 11 (or whatever your choose)

i hope this info helps and saves some people a lot of time.

eric
Reply With Quote
  #83  
Old 11-27-2006, 04:17 PM
DeMagH DeMagH is offline
 
Join Date: Oct 2006
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

it should be hooked correctly in my forums "using 3.6.2" but it doesn't seem to work
here is my code, please let me know if something is wrong: "i use field5 by the way"
Code:
if ($user['field5'] == 'Egypt')
{
	$userdata->set('usergroupid', 14);
}
if ($user['field5'] == 'Canada')
{
        $userdata->set('usergroupid', 18);
}
if ($user['field5'] == 'Saudi Arabia')
{
        $userdata->set('usergroupid', 15);
}
if ($user['field5'] == 'United Arab Emirates')
{
        $userdata->set('usergroupid', 16);
}
if ($user['field5'] == 'United Kingdom')
{
        $userdata->set('usergroupid', 17);
}
if ($user['field5'] == 'United States')
{
        $userdata->set('usergroupid', 10);
}
if ($user['field5'] == 'Other')
{
        $userdata->set('usergroupid', 19);
}
checked usergroupid matching
checked field matching
checked case sensitivity
is there anything else to check?!

note:
my field type is single selection menu, should i change it into radio buttons?

note:
here how the code is appearing in the plugins manager section:
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'] == 'Egypt')
{
    $userdata->set('usergroupid', 14);
}
if ($user['field5'] == 'Canada')
{
        $userdata->set('usergroupid', 18);
}
if ($user['field5'] == 'Saudi Arabia')
{
        $userdata->set('usergroupid', 15);
}
if ($user['field5'] == 'United Arab Emirates')
{
        $userdata->set('usergroupid', 16);
}
if ($user['field5'] == 'United Kingdom')
{
        $userdata->set('usergroupid', 17);
}
if ($user['field5'] == 'United States')
{
        $userdata->set('usergroupid', 10);
}
if ($user['field5'] == 'Other')
{
        $userdata->set('usergroupid', 19);
}
Reply With Quote
  #84  
Old 11-29-2006, 11:47 AM
DeMagH DeMagH is offline
 
Join Date: Oct 2006
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

bumping thread
Reply With Quote
  #85  
Old 11-30-2006, 02:32 PM
amnesia623 amnesia623 is offline
 
Join Date: Jul 2006
Location: Glendale, AZ
Posts: 226
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

does this work in 3.6.4?
Reply With Quote
  #86  
Old 11-30-2006, 06:43 PM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes. It's still running unchanged on my site.
Reply With Quote
  #87  
Old 11-30-2006, 11:00 PM
wes_517 wes_517 is offline
 
Join Date: Mar 2006
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is VERY close to exactly what my members are asking for, but I would need one small change...

Most of my site is closed off to non-members, and so to make sure who I am adding, I have to moderate all new users for privacy reasons...

So instead of adding new users directly to the group, what would I need to change to add them into the moderation queue instead?

I'm decent with PHP and Mysql, but still learning ins and outs of vbulletin...

any help?
--edit 1--
Thinking about this more, is that POSSIBLE for a primary group? (if the user logs in while their primary group is still under review, wouldn't they then not belong to ANY group and be denied access?)

--edit 2--

I hacked some code out, it may not be pretty, but it's working...

https://vborg.vbsupport.ru/showthrea...31#post1129131

since it modifies the secondary user, i posted it over there... anyone have an idea on the edit 1 question? can that be done or would it throw a fit because they wouldn't have a group yet?
Reply With Quote
  #88  
Old 12-08-2006, 01:36 PM
salata salata is offline
 
Join Date: Nov 2003
Posts: 252
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i am having diffulculty getting this to work for me, i am using 3.5.4

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 25
        $user = $db->query_first("
			SELECT field25
			FROM " . TABLE_PREFIX . "userfield
			WHERE userid = " . $vbulletin->userinfo['userid'] . "
		");


		if ($user['field25'] == 'No')
		{
			$userdata->set('usergroupid', 36);
		}]]></phpcode>
	</plugin>
</plugins>
Reply With Quote
  #89  
Old 12-21-2006, 06:19 AM
yingzhou's Avatar
yingzhou yingzhou is offline
 
Join Date: Oct 2006
Location: Ho Chi Minh
Posts: 254
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

can this mod work on vb 3.6.x? Im using 3.6.4 now.
Reply With Quote
  #90  
Old 12-25-2006, 05:37 PM
DeMagH DeMagH is offline
 
Join Date: Oct 2006
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by yingzhou View Post
can this mod work on vb 3.6.x? Im using 3.6.4 now.
yeah worked for me in 3.6.2
Reply With Quote
  #91  
Old 01-12-2007, 07:18 PM
Mum Mum is offline
 
Join Date: Jun 2006
Location: New Zealand
Posts: 660
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I installed this, but when i registered a new user to test it, it hasn't added it to the group at all. This is my very first plug in, so may be something i've done wrong. PLease help

Quote:
// 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')
{
$userdata->set('usergroupid', 11);

if ($user['field5'] == 'Male')
{
$userdata->set('usergroupid', 13);
}
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:43 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05760 seconds
  • Memory Usage 2,323KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (7)bbcode_code
  • (1)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete