Check if user is in group
-
Hey there! So, I've been customizing a theme lately, and I was wondering if there was a way to check if a user is in a group, for example:
<!-- IF user.groups.admin -->
, or perhaps even with JavaScript. I'd like to be able to add extra content to a user's profile if they are in a certain group, (for example, perhaps admins could have a special image on their profile).Please let me know if there's any way of doing this, thank you!
EDIT: Or even being able to do this per-user would be absolutely fine for me! Thanks again.
-
@itsCrafted I believe you'd want to have a plugin (or your theme, rather, since themes are plugins too) listen to the
filter:users.get
hook, and add that information as necessary.Save the value as a boolean, and then you'll be able to use it in the
<!-- IF -->
-
- Notice the hook listener registered here: https://github.com/NodeBB/nodebb-plugin-quickstart/blob/master/plugin.json#L7
- Corresponding to a method in the plugin library itself: https://github.com/NodeBB/nodebb-plugin-quickstart/blob/master/library.js#L7
You'll want to listen to the hook I mentioned above, and make a call to
groups.isMember()
to check group membership status, and then save it to the corresponding users' information.