User Group Field is a Craft CMS plugin with a field type that lets you select one or more user groups.
Visit the User Group Field Plugin page for all documentation, guides, pricing and developer resources.
By default Craft::$app->getUserGroups()->getAllGroups();
is called for every element that has a user group field, requesting all the groups which won't change between entries, unless it's a CP request and a user group is added, edited or removed.
This data can be cached per url by adding a flag to the following calls -
{% set groups = entry.userGroupFieldHandle.getGroups($cache = true) %}
{% if entry.userGroupFieldHandle.inGroup(currentUser, $cache = true) %}
{% if entry.userGroupFieldHandle.canAccess(currentUser, $cache = true) %}
Originally created by the team at Superbig.
Get in touch with us via the User Group Field Support page or by creating a Github issue
User Group Field is licensed under the MIT license, meaning it will always be free and open source โ we love free stuff! If you'd like to show your support to the plugin regardless, Sponsor development.