Show BUTTON only to staff users

I added some button via script in the <head>...</head> part at this page:
/admin/customize/themes/2/common/head_tag/edit

this way
<script type="text/discourse-plugin" version="0.4">
api.onToolbarCreate(toolbar => {
toolbar.addButton({
id: "times-circle",
});
});
</script>

How can I make this button be visible only to staff users (moderators, admin) and users in group called “vip-group”?

1 Like

Hi! Simple as this

<script type="text/discourse-plugin" version="0.8">
const user = api.getCurrentUser();

// find if user is in vip-group
const isInVipGroup = user.groups.some(({name}) => name === "vip-group");

if (user.staff || isInVipGroup) {
  api.onToolbarCreate(toolbar => {
    toolbar.addButton({
      id: "times-circle",
    });
  });
}
</script>
6 Likes

Great! It’s working!
Also I found these topics, that may be userful for smbd.

2 Likes

@Ed_Bobkov I’ve edited snippet to work for your certain group type. Don’t know if you have seen that, just a reminder.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.