12

I don't think that there currently is a plugin option right now, but keep an eye on the craft plugin page. However, given your requirement to "automatically assign users to different membership groups", I think you would need to write your own regardless. That is pretty specific and would require that you have your user groups set up to match the ...


9

According to the docs, the userModel.isInGroup() method takes a "user group model, its handle, or ID" – in other words, it can only test for membership in a single group, not several. What you want in this case is the or operator: {% if currentUser and (currentUser.isInGroup('userGroup1') or currentUser.isInGroup('userGroup2')) %} {# secret content #} {...


8

If anyone comes here looking for this answer for Craft 3 the function you are looking for is Craft::$app->getRequest()->getIsCpRequest()


7

Under Settings > Users > Settings Tab there is an option to allow public registration and Default User Group with a drop down that lets you select a user group. If you need more flexibility, you could also write a simple plugin with an init function defined in the primary plugin class that listens to the saveUser event, and assigns a user group based on ...


7

If you're looking for a Craft 3 solution, I just got this set up on a project and hope it helps someone else out. First you'll need to add a custom field to your form. If you want your user to choose which field, then go with a dropdown or radio button and adjust the plugin logic below. My scenario required me using a hidden field and auto-filling in the ...


6

The setting still works, but keep in mind that for it to take effect, A) you have to be registering a user through a custom registration form on the front end, and B) you have to be logged out. Without those conditions, it’s not technically public registration. Default user group assignment has always taken place after the user was saved, and after the ...


6

Yes there is, craft()->request->isCpRequest() returns whether the request is from the CP or not.


6

Going to chime in here as I ran into a similar issue, and solved it a bit differently. Instead of using group handles I was using a dynamic set of Group IDs. However, the problem still remains that isInGroup() doesn't support an array of handles or ids. So you gotta run some checks. And, I think you can be little more dynamic using IDs. {% set ...


5

As Fabio pointed out, i'd managed to miss the isInGroup method. Slightly embarrassing! So for anyone else looking to do what i asked, i changed my code to the following: {% if entry.author.isInGroup('authors') %} and it works perfectly now.


5

Before you can allow any type of user groups you will need at a minimum of the Client version of Craft. To allow public registration, you will need the Professional version. Only the Professional version will allow you to have public registration on our site. Here is more information about users and user groups. To add additional fields to your registration ...


5

As carlcs said, this is already working as expected. Craft only enforces content validation rules for enabled entries (not including drafts), and most people prefer that behavior. If you want to change that behavior, you can write a plugin that provides its own entry validation logic, by latching onto the entries.onBeforeSaveEntry event. Just put this in ...


5

Just checked eager-loading a text field in a template and by eager-loading it you are actually converting the field to an array and therefore unable to template it as usual. Eager-loading is generally only useful on fields like categories, assets, and matrixes.


4

This answer was originally written for Craft 2. For a Craft 3 solution, see Ryan's answer above. I literally just worked through this problem last week. Ran into the same issue, so I reached out to P&T. Turns out there is a "catch"... For a new user, the $_POST['groups'] value is passed as an empty array. And because of the order that it's ...


4

assignUserToGroups has $groupIds parameter (int / array) preset to null. From the docs: assignUserToGroups($userId, $groupIds = null) So calling the function without that parameter set should do it: craft()->userGroups->assignUserToGroups(1);


4

If the users will never have access to the Craft CP then you can use categories or any other applicable field type (i.e. dropdown, radio buttons, tags, etc.) to create differentiation between the users. It really just depends on how accessible and/or 'static' you want the groups or sudo-groups to be. Categories and tags for example can be created dynamically,...


4

You can create a plugin that adds custom user permissions via the registerUserPermissions hook.


4

You'd need to do this from a plugin that has a controller that calls UserGroupsService->assignUserToGroups().


4

Your code to get a user returns a UserModel (as can be seen from the Full Class Reference docs): $user = craft()->users->getUserById($id); You can then get the user groups the $user is a member of usinggetGroups()(from the UserModel class): $user_groups = $user->getGroups();


4

As other answers have touched on, the behaviour you're seeing is by design. I've written a plugin called Always Validate which will make Craft validate all disabled entries and categories – including entry drafts or entries saved by users not permitted to publish – which should solve your issue.


4

I get bit by this a lot. Just like @Stephen Lewis suggested - make sure you are not logged into the same browser. For example, log into the CP with Safari (or whatever) and then use Chrome to actually register an account via your front-end form.


3

To have a new user automatically assigned to a user group, there are two easy ways to do it. (1) If the user registers through a front-end form: You can pre-set their user group by going to Settings > Users > Settings, and selecting the "Allow public registration?" checkbox. This will reveal a dropdown menu, from which you can select their destination user ...


3

You could get the IDs of all users belonging to a group, and use these IDs prefixed with not as the id parameter in a second craft.users ElementCriteriaModel: {% set userIds = craft.users.group('group1, group2, group3').ids() %} {% set users = craft.users.id('and, not ' ~ userIds|join(', not ')) %}


3

You can use the Control Panel User Group plugin to automatically add special classes to the <body> tag in the CP. Once those classes are in place, it's easy to use CSS or JavaScript to hide fields from certain user groups (or trigger other behavior based on user group status). * Disclaimer: I'm the author of all of those plugins. :)


3

As far as I know there is no way to do this without a plugin. However, developing a plugin for this is not difficult. In your form you would want to add an additional drop-down, multi-select, or checkbox field with your groups listed. Then in your plugin, create a listener in your plugin's init method that listens for the users.saveUser event, and ...


3

There is no native way to limit which sources appear in the asset window. I imagine it can be accomplished with a custom field type. This would be a great feature for future releases; I recommend adding it to the Feature Requests forum.


3

That's the idea behind Drafts, to store entries not yet ready to publish, unfinished ones so to speak. I think it does make sense to not validate the fields. Good feature!


3

So it seems the only way to achieve this is to assign the user to the group, not the other way round (assign the group to the user). So once my user has saved I can call following: craft()->userGroups->assignUserToGroups($user->id, $groupId);


3

I assume you have basic knowledge in creating plugins, if not I suggest visiting the docs. It's actually pretty easy to achieve your goal. Create a Plugin and store an array of permission's in it's settings <!-- first permission --> <input class="text" type="text" name="permissions[]" value="" autofocus="" autocomplete="off"> <!-- 2nd ...


3

You can assign a user to certain groups via Craft::$app->getUsers()->assignUserToGroups($user->id, [1,2,3]); Would assign them to the groups with the ids 1, 2 and 3


3

If you setup a User Group with the same handle as the Site you want them to have access to, this could be fairly easy. Let's say you have a site called "Acme" setup in the Sites settings. You also created a corresponding User Group called "Acme." The handles for the Acme Site and Acme User Group are both "acme." When you're on ...


Only top voted, non community-wiki answers of a minimum length are eligible