<p>This should do the trick...</p>

<pre><code>$user-&gt;admin = true;
</code></pre>

<p>That data is part of the UserModel, so be sure to add it before the <code>saveUser</code> call.</p>

<p>Being a full-blown admin not technically part of setting permissions. If the user is an admin, that supersedes all other permissions settings.</p>

CC BY-SA 3.0
2017-03-16T23:36:07.900Z
2017-03-16T23:36:07.900Z
Lindsey D
<p>I'd like to add admin privileges to a user I'm creating like so: </p>

<pre><code>  if($user == null)
  {
    $firstName = $_GET['firstName'];

    $lastName = $_GET['lastName'];
    $userName = $firstName . $lastName;
    $user = new UserModel();

    $user-&gt;username   = $userName;
    $user-&gt;email      = $email;
    $user-&gt;firstName  = $firstName;
    $user-&gt;lastName   = $lastName;

    craft()-&gt;users-&gt;saveUser($user);

    $permissions = [HOW DO I SET ADMIN PERMS?]
    craft()-&gt;userPermissions-&gt;saveUserPermissions($user['id'], $permissions)

}
</code></pre>

CC BY-SA 3.0
2017-03-17T00:04:25.237Z
I don't know the context that you're doing this in, but needless to say, generally speaking be cautious in creating admins programatically.  Especially if it's a front-end request from untrusted input.
Brad Bell
<plugins><admin><permissions>
Is it possible to grant admin permissions via plugins through userPermissions->saveUserPermissions?
# Is it possible to grant admin permissions via plugins through userPermissions->saveUserPermissions?

(Asked by: username_0 on 2017-03-16)

I'd like to add admin privileges to a user I'm creating like so: 
  if($user == null)
  {
    $firstName = $_GET['firstName'];

    $lastName = $_GET['lastName'];
    $userName = $firstName . $lastName;
    $user = new UserModel();

    $user->username   = $userName;
    $user->email      = $email;
    $user->firstName  = $firstName;
    $user->lastName   = $lastName;

    craft()->users->saveUser($user);

    $permissions = [HOW DO I SET ADMIN PERMS?]
    craft()->userPermissions->saveUserPermissions($user['id'], $permissions)

}

**Tags:** plugins, admin, permissions
> **Comments:**
> **username_1**: I don't know the context that you're doing this in, but needless to say, generally speaking be cautious in creating admins programatically.  Especially if it's a front-end request from untrusted input.  

---

## 1 answers

### Answer by username_2 on 2017-03-16. Score: 2 | Accepted answer

This should do the trick...
$user->admin = true;

That data is part of the UserModel, so be sure to add it before the saveUser call.
Being a full-blown admin not technically part of setting permissions. If the user is an admin, that supersedes all other permissions settings.


---

