Add a user to a current group

For Joomla! 5.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
cscotthosting
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Mon Jan 02, 2023 3:14 pm

Add a user to a current group

Post by cscotthosting » Mon Apr 01, 2024 11:07 am

I have created a group, progamatically. How do I add a user to the new group, programtically?

jUserHelper::addUserToGroup($userid,$groupid) is outdated.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30869
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Add a user to a current group

Post by Per Yngve Berg » Mon Apr 01, 2024 11:28 am


User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17411
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Add a user to a current group

Post by toivo » Mon Apr 01, 2024 11:58 am

Try something like this (not tested):

Code: Select all

use Joomla\CMS\User\UserHelper;

if (!UserHelper::addUserToGroup($userId, $groupId)) {
	return false;
}
Toivo Talikka, Global Moderator


Post Reply

Return to “Joomla! 5.x Coding”