---
title: "How to Add a User to a Joomla Group Programmatically - Joomla"
description: "Learn how to add a user to a specific Joomla group using PHP. This script is handy for automating user management tasks or integrating Joomla with oth"
url: "https://www.tassos.gr/docs/joomla/tutorials/add-user-to-user-groups"
date: "2026-05-01T15:47:40+00:00"
language: "en-GB"
---

[ Home ](https://www.tassos.gr/index.php?option=com_content&view=category&layout=blog&id=24&Itemid=1088) / [ Joomla ](https://www.tassos.gr/index.php?option=com_content&view=category&id=91) / [ Tutorials ](https://www.tassos.gr/index.php?option=com_content&view=category&id=92)

#  How to Add a User to a Joomla Group Programmatically

Heads up! This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

Learn how to add a user to a specific Joomla group using PHP. This script is handy for automating user management tasks or integrating Joomla with other systems. It uses Joomla's Factory class to load a user, update their group assignments, and save the changes.

 ```

use Joomla\CMS\Factory;
use Joomla\CMS\User\UserFactoryInterface;

// Define the user ID to be updated
$userID = 150;

// Load the user object
$userFactory = Factory::getContainer()->get(UserFactoryInterface::class);
$user = $userFactory->loadUserById($userID);

// Define the new group ID to add the user to
$newGroupId = 8;

// Check if the user is not already in the specified group
if (!in_array($newGroupId, $user->getAuthorisedGroups()))
{
    // Add the new group ID to the user's groups
    $user->groups[] = $newGroupId;
}

// Attempt to save the updated user object
if (!$user->save())
{
    // Output an error message if saving fails
    echo "Failed to add user to the group: " . $user->getError();
}
else
{
    // Output a success message if saving succeeds
    echo "User successfully added to the group.";
}
```

 To add a user to the Super Users group, you must have Super Users privileges.

 Last updated on Mar 5th 2026 14:03

## Schema

```json
{
    "@context": "https://schema.org",
    "@type": "BreadcrumbList",
    "itemListElement": [
        {
            "@type": "ListItem",
            "position": 1,
            "name": "Home",
            "item": "https://www.tassos.gr"
        },
        {
            "@type": "ListItem",
            "position": 2,
            "name": "Home",
            "item": "https://www.tassos.gr/docs"
        },
        {
            "@type": "ListItem",
            "position": 3,
            "name": "Joomla",
            "item": "https://www.tassos.gr/docs/joomla"
        },
        {
            "@type": "ListItem",
            "position": 4,
            "name": "Tutorials",
            "item": "https://www.tassos.gr/docs/joomla/tutorials"
        },
        {
            "@type": "ListItem",
            "position": 5,
            "name": "How to Add a User to a Joomla Group Programmatically",
            "item": "https://www.tassos.gr/docs/joomla/tutorials/add-user-to-user-groups"
        }
    ]
}
```

```json
{
    "@context": "https://schema.org",
    "@type": "Article",
    "mainEntityOfPage": {
        "@type": "WebPage",
        "@id": "https://www.tassos.gr/docs/joomla/tutorials/add-user-to-user-groups"
    },
    "headline": "How to Add a User to a Joomla Group Programmatically",
    "image": {
        "@type": "ImageObject",
        "url": "https://www.tassos.gr/"
    },
    "publisher": {
        "@type": "Organization",
        "name": "Tassos",
        "logo": {
            "@type": "ImageObject",
            "url": "https://www.tassos.gr/https://www.tassos.gr/media/brand/logo-text.png"
        }
    },
    "author": {
        "@type": "Person",
        "name": "Tassos Marinos",
        "url": "https://www.tassos.gr/docs/joomla/tutorials/add-user-to-user-groups"
    },
    "datePublished": "2025-04-23T14:12:47+03:00",
    "dateCreated": "2025-04-23T14:12:47+03:00",
    "dateModified": "2026-03-05T14:35:15+02:00"
}
```
