Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-22-2010, 04:13 AM
razec razec is offline
 
Join Date: Nov 2009
Posts: 28
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Change primary usergroup via PHP

I'm just curious as to what the best practice is for changing a user's primary usergroup through code. I tried searching the vB4 forum here for information on it but I didn't find anything. Is there a function that handles it, or a guide that I can reference with more information?

Can I just do it with something like this? Mind you this could be completely off which is why I haven't even tried it yet.

Code:
$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$vbulletin->userinfo['usergroupid'] = $new_group = $userdata->save();

This is based on observations I made in register.php. I'm pretty sure it's not correct because I'm probably interpreting what's going on wrong. The point of this change is to allow the user to set what type of user they are, and in doing so this will change their primary group to match their selection. This takes place after the registration is complete, but I referred to register.php because I knew that's a place where the user's group (and other information) would be set/changed in code.
Reply With Quote
  #2  
Old 01-22-2010, 10:08 AM
ForumsMods ForumsMods is offline
 
Join Date: Aug 2007
Location: Argentina
Posts: 667
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$userdata =& datamanager_init('User'$vbulletinERRTYPE_ARRAY);
$userdata->set('usergroupid'$new_group);
$userdata->save(); 
Reply With Quote
  #3  
Old 01-22-2010, 08:46 PM
razec razec is offline
 
Join Date: Nov 2009
Posts: 28
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I get an error when this code runs:

Quote:
Fatal error:

* A required field called username is missing or has an invalid value.

Unable to proceed with save while $errors array is not empty in class vB_DataManager_User in [path]/includes/class_dm.php on line 849
The code I'm using is:

Code:
			$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
			$userdata->set('usergroupid', $new_group);

			$userdata->save();
which is what I copied from your post. Any idea as to why it's throwing that error?
Reply With Quote
  #4  
Old 01-22-2010, 08:47 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You should have something like this before calling set,

PHP Code:
$userdata->set_existing(fetch_userinfo($userid)); 
Reply With Quote
  #5  
Old 01-23-2010, 04:06 AM
razec razec is offline
 
Join Date: Nov 2009
Posts: 28
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ahh, got it. That did the trick! Thank you.
Reply With Quote
  #6  
Old 02-29-2016, 04:52 AM
khininger khininger is offline
 
Join Date: Aug 2009
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

huge thank you for this thread (idk why im not able to thank the posts directly).

i was looking for this for years. using it for the "delete my account" issues, switching them to another usergroup that hides them from members list and locks them out of forums, giving error message that they have deactivated their account, but can reactivate if they changed their mind. thank you.
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 09:46 PM.


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.04776 seconds
  • Memory Usage 2,207KB
  • Queries Executed 11 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (2)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete