Answers.Body: <p>Are they in the administrators group? Since then you might be able to do something like (untested):</p>
  
  <pre><code>CRM.api3('GroupContact', 'get', {
    "contact_id": "user_contact_id", // use this exact string to mean current user
    "group_id": "Administrators"
  }).then(function(result) {
    if (result.count == 0) {
      // Not in the admin group
      // ** do your removal stuff here **
    }
  });
  </code></pre>
  
  <p>There is also CRM.checkPerm() to check a CMS permission. See e.g. <a href="https://github.com/civicrm/civicrm-core/blob/5.18.4/templates/CRM/Tag/Page/Tag.tpl#L123" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/5.18.4/templates/CRM/Tag/Page/Tag.tpl#L123</a>, e.g. <code>CRM.checkPerm('administer reserved tags')</code></p>
  
  <pre><code>if (!CRM.checkPerm("administer CiviCRM")) {
    // do your removal stuff
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-24T01:48:04.847Z
Answers.Text: I am not familiar with the administrators group. It says 0 records are in it. But I tested with both admin and non-admin roles and it did not apply my jQuery.
Answers.UserDisplayName: Andy Burns
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-24T01:49:24.650Z
Answers.Text: Oh ok. Do you mean administrator role in the CMS (e.g. Drupal)? Or a civi ACL maybe?
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-24T01:54:43.663Z
Answers.Text: I mean the administrator role in WP, not using ACL's. Using that group method would be fine but I worry that users could somehow add to that group? Seems like an obvious loophole. That group is only for ACL usage I assume. Alternatively, I have 4 non-admin user civi groups that all non-admins get put into I could apply the code to.
Answers.UserDisplayName: Andy Burns
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-24T02:03:31.543Z
Answers.Text: I updated answer to include CRM.checkPerm(), to check a CMS permission.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-24T02:10:13.137Z
Answers.Text: Sorry, I am not able to put that all together...
Answers.UserDisplayName: Andy Burns
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-24T02:12:47.837Z
Answers.Text: Go to Administer - users and permissions - permissions. On that page near the middle there's a link to "wordpress access control". That page has a list of permissions. If you use one of those permission strings inside CRM.checkPerm() to tell if they have that permission or not, it returns true or false for the logged in user. Looking at the wordpress demo, the "CiviCRM Administrator" role has "administer CiviCRM" permission, which seems as good as any to use as the string to put in CRM.checkPerm("administer CiviCRM").
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-05T00:00:45.070Z
Answers.Text: For some unknown reason, if I try to use a different permission than "administer CiviCRM", the check does not work.
Answers.UserDisplayName: Andy Burns
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-05T01:01:58.520Z
Answers.Text: It's case-sensitive is all I can think at the moment. Maybe also as listed on that permissions screen it has a prefix that you don't include, i.e. don't include the `CiviCRM:` or `CiviEvent:` part at the beginning.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-05T18:11:35.110Z
Answers.Text: It's not that issue. I have the perm entered properly. I am using .extra.tpl files. Frustrating as if I want to customize screen per user role other than non-admin I am out of luck.
Answers.UserDisplayName: Andy Burns
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-24T01:16:59.700Z
Answers.LastActivityDate: 2019-10-24T02:17:10.083Z
Answers.LastEditDate: 2019-10-24T02:17:10.083Z
Answers.UserDisplayName: Demerit
Body: <p>There are several instances where I want to remove some buttons, inputs, tabs, etc on various screens for non-admin users. For instance, on the Event Search screen in this template</p>
  
  <p><code>CRM/Event/Form/Search.extra.tpl</code> I have</p>
  
  <pre><code>&lt;script&gt;
  {literal}
  //remove smart group creation
  CRM.$(function remove_smart_group_creation($) {
   $('#task option[value=12]').remove();
  });
  
  //remove group add contacts
  CRM.$(function remove_group_add_contacts($) {
   $('#task option[value=2]').remove();
  });
  
  //remove delete participants
  CRM.$(function remove_delete_participants($) {
   $('#task option[value=4]').remove();
  });
  &lt;/script&gt;
  {/literal}
  </code></pre>
  
  <p>How could I exempt the administrator role?</p>
  
Tags: <custom-templates><jquery>
Title: Removing elements for non-admin users
ThreadText: # Removing elements for non-admin users
  
  (Asked by: username_0 on 2019-10-24)
  
  There are several instances where I want to remove some buttons, inputs, tabs, etc on various screens for non-admin users. For instance, on the Event Search screen in this template
  
  `CRM/Event/Form/Search.extra.tpl` I have
  
  ```
  <script>
  {literal}
  //remove smart group creation
  CRM.$(function remove_smart_group_creation($) {
   $('#task option[value=12]').remove();
  });
  
  //remove group add contacts
  CRM.$(function remove_group_add_contacts($) {
   $('#task option[value=2]').remove();
  });
  
  //remove delete participants
  CRM.$(function remove_delete_participants($) {
   $('#task option[value=4]').remove();
  });
  </script>
  {/literal}
  
  ```
  
  How could I exempt the administrator role?
  
  **Tags:** custom-templates, jquery
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-10-24. Score: 2 | Accepted answer
  
  Are they in the administrators group? Since then you might be able to do something like (untested):
  
  ```
  CRM.api3('GroupContact', 'get', {
    "contact_id": "user_contact_id", // use this exact string to mean current user
    "group_id": "Administrators"
  }).then(function(result) {
    if (result.count == 0) {
      // Not in the admin group
      // ** do your removal stuff here **
    }
  });
  
  ```
  
  There is also CRM.checkPerm() to check a CMS permission. See e.g. <https://github.com/civicrm/civicrm-core/blob/5.18.4/templates/CRM/Tag/Page/Tag.tpl#L123>, e.g. `CRM.checkPerm('administer reserved tags')`
  
  ```
  if (!CRM.checkPerm("administer CiviCRM")) {
    // do your removal stuff
  }
  
  ```
  
  > **Comments:**
  > **username_0**: I am not familiar with the administrators group. It says 0 records are in it. But I tested with both admin and non-admin roles and it did not apply my jQuery.  
  > **username_1**: Oh ok. Do you mean administrator role in the CMS (e.g. Drupal)? Or a civi ACL maybe?  
  > **username_0**: I mean the administrator role in WP, not using ACL's. Using that group method would be fine but I worry that users could somehow add to that group? Seems like an obvious loophole. That group is only for ACL usage I assume. Alternatively, I have 4 non-admin user civi groups that all non-admins get put into I could apply the code to.  
  > **username_1**: I updated answer to include CRM.checkPerm(), to check a CMS permission.  
  > **username_0**: Sorry, I am not able to put that all together...  
  > **username_1**: Go to Administer - users and permissions - permissions. On that page near the middle there's a link to "wordpress access control". That page has a list of permissions. If you use one of those permission strings inside CRM.checkPerm() to tell if they have that permission or not, it returns true or false for the logged in user. Looking at the wordpress demo, the "CiviCRM Administrator" role has "administer CiviCRM" permission, which seems as good as any to use as the string to put in CRM.checkPerm("administer CiviCRM").  
  > **username_0**: For some unknown reason, if I try to use a different permission than "administer CiviCRM", the check does not work.  
  > **username_1**: It's case-sensitive is all I can think at the moment. Maybe also as listed on that permissions screen it has a prefix that you don't include, i.e. don't include the `CiviCRM:` or `CiviEvent:` part at the beginning.  
  > **username_0**: It's not that issue. I have the perm entered properly. I am using .extra.tpl files. Frustrating as if I want to customize screen per user role other than non-admin I am out of luck.  
  
  ---
  
  