Make user roles editable for an "editor" or assign a certain role to every new/created user

Hello all!

I need for a certain project the option that an editor can also assign roles (of course below “Admin”) to other users to manage the membership of an association.

I tried the plugin “Capabilities” at first -> editor can create and edit users (great), but unfortunately not set the “role”.

Basically it would be enough, if all newly created members/users get a certain (adjustable) role, for 99% this is the same role anyway (it’s an S2 level).

Of course, I would prefer a solution without a plugin.


What should be achieved is the following:

New members are created manually each time after they have requested membership via the contact form (a “Manual User Review”). Free registration should not exist.

Thinking about it a bit, I need exactly the same for another project: Here members are submitted via the S2member form, but also manually raised to e.g. level2.

I do not want to give admin rights to the editors / maintainers, should be clear … :grinning:


I am happy about all hints!

Best regards and Thanks!

Hi Hans.

So you want your helpers to change the user’s role without having admin access, is that what you mean?

If so, you’ll need a custom script, I guess. This article can help: https://s2member.com/kb-article/rolescapabilities-via-php/

I hope that helps! :slight_smile:

Dear Christian,

Thanks for the answer, but could there be a simpler solution?

Is it possible to set the role for newly created users via config.php to e.g. s2member_level_1 by default? (what you could normally define in “Settings -> General -> Standard role for new users”)

That would be sufficient in that case.

Adding a backend function (as suggested) would certainly be an elegant way, but I can’t program that myself, I know some php to modify templates and post-outputs etc.and know CSS quite well, but I’m mostly a designer and “frontender”.
And this project is not budgeted well either, so I can’t pay someone to program this.

Best regards and Thanks!

Hi Hans.

I see…

To set a default role for registrations, you can use this hack: https://www.primothemes.com/forums/viewtopic.php?f=36&t=2760

If you have s2Member Pro, the free registration pro-form lets you set the level the user gets. WP Admin > s2Member Pro > PayPal Pro-Forms > Free Registration

Does that help? :slight_smile:

Hi Christian,

thanks for your hint - sounds good so far.

BUT:
a) I think there is a fault in the snippet here (closing “php”-tag) - please see below.
https://www.primothemes.com/forums/viewtopic.php%3Ff=36&t=2760.html#

If code is used inside an “mu-plugin” you must in no case close the <?php … with an ?> at the end.
Is this correct? I had not read that anywhere until now …

b) Could please complement the code example with a hint which positions I exactly have to adapt?

<?php add_filter("ws_plugin__s2member_force_default_role", "default_role"); function default_role($default = "contributor"){ return "contributor"; }

Do I have to change both “contributor” entries to “s2member_level1” and is the spelling correct for the s2-level?

Reason for asking in more detail

I tried the mu-plugin with the code as original ( the “>” at the end ) and some dashboard functions like “search user” or reset password didn’t work etc. (so I assumed that parts of the core-files weren’t porcessed), at first I could restore some functions by emptying the the mu-plugin but after a few relaods, the dashboard was a complete “whitescreen”.
Even a complete deletion of the mu-plugin didn’t help.
So I had to do a full restore of a backupped version of the WP-installation.

Is the snippet above tested with newer versions of WP and S2? Could you check / find out?
I could “pm” a plugin list if that haleps, but the only one which is role-related is “PublishPress Capabilities” - see the beginning of thread.

Needing a full backup is always nerve-racking, as you can only rely on the backups 99% of the time.

Best regards and thanks!


By the way: I own a “Pro” licence, but it seems this won’t help in this case. As I mentioned above, we have no submission forms at all on this page - neither normal nor “pro” forms. People contact via contact-form and are created as users manually then.

Even a complete deletion of the mu-plugin didn’t help.

That is very weird. The problem that an early ouput header can cause, is only for the time it’s ran, not a permanent damage to the code in other files. It sounds like you were getting a cache of the time with the problem.

If you have WP_DEBUG enabled, instead of just white, you’d likely get a more descriptive error. Also the PHP errors log may have an entry for the problem.

But it really is most likely just an output header too early in the flow of WordPress (e…g a space or newline after the closing PHP tag).

If code is used inside an “mu-plugin” you must in no case close the <?php … with an ?> at the end. Is this correct? I had not read that anywhere until now …

I think I’ve seen it done both ways, but it’s safer to not close it, to avoid an output too early by mistake.

Do I have to change both “contributor” entries to “s2member_level1” and is the spelling correct for the s2-level?

Yes, you can change both to the one you want, but in that code the return is the important one. “s2member_level1” is fine. https://s2member.com/kb-article/rolescapabilities-via-php/

<?php
add_filter('ws_plugin__s2member_force_default_role', 'default_role');
function default_role($default = '') {
    return 's2member_level1';
}

People contact via contact-form and are created as users manually then.

If you’re creating him manually, the role can be set at that time too, no need for the custom code, but automation is fine too, of course.

:slight_smile: