Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-16T23:36:07.900Z
Answers.LastActivityDate: 2017-03-16T23:36:07.900Z
Answers.UserDisplayName: Lindsey D
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-17T00:04:25.237Z
Comments.Text: 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.
Comments.UserDisplayName: Brad Bell
Tags: <plugins><admin><permissions>
Title: Is it possible to grant admin permissions via plugins through userPermissions->saveUserPermissions?
ThreadText: # 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.
  
  
  ---
  
  