vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Change primary usergroup via PHP (https://vborg.vbsupport.ru/showthread.php?t=233826)

razec 01-22-2010 04:13 AM

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.

ForumsMods 01-22-2010 10:08 AM

PHP Code:

$userdata =& datamanager_init('User'$vbulletinERRTYPE_ARRAY);
$userdata->set('usergroupid'$new_group);
$userdata->save(); 


razec 01-22-2010 08:46 PM

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?

Adrian Schneider 01-22-2010 08:47 PM

You should have something like this before calling set,

PHP Code:

$userdata->set_existing(fetch_userinfo($userid)); 


razec 01-23-2010 04:06 AM

Ahh, got it. That did the trick! Thank you.

khininger 02-29-2016 04:52 AM

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.


All times are GMT. The time now is 06:44 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.01055 seconds
  • Memory Usage 1,725KB
  • 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
  • (2)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete