How can I set secondary user group via XF options?

XDinc

New Member
Reactions
1
Hello @Xon
I used PHP callback to get user groups with XF\Option\UserGroup::renderSelect.

4226


As you can see below, there is no problem at this stage.

4227


I've Templater.php file, base class name: XF\Template\Templater
How can I set in this php file if secondary user group is xUserGroup via PHP Could you please anyone let me learn or see sample?

Code:
namespace Validator\XF\Template;

class Templater extends XFCP_Templater
{
    public function fnUsernameLink($templater, &$escape, $user, $rich = false, $attributes = [])
    {
      
        $isAddonEnabledGlobally =! \XF::options()->offsetGet('enableXAddon');

        if(!$isAddonEnabledGlobally)
        {
      
/**if secondary group_id == xUserGroup*/
               { My codes......
               }
        }
        return $response;
    }
}


I know this service as below but I do not want to add new user group I want to use the group specified in the option.

PHP:
      /** @var \XF\Service\User\UserGroupChange $userGroupChange */
      $userGroupChange = \XF::service('XF:UserGroupChange');
      $userGroupChange->addUserGroupChange($user->user_id, '<a key describing the change>', [<array of user group ids to add to>]);

I 've not reached to success result yet with the my codes but I have to try, and I think I need to learn that.
Thank you for your help.
 

Absolutely I agree, I tried, but no one answered.

You are looking for the XF\Entity\User::isMemberOf function, something like;

PHP:
if ( $user instanceof \XF\Entity\User && $user->isMemberOf($xUserGroup))
{
...
}

Thank you very much for this information and support.
it works well.
 
Last edited:

Users who are viewing this thread

Back
Top