latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Assigning a default user role

Home Forums Community Forum Assigning a default user role

This topic contains 15 replies, has 6 voices. Last updated by  Shawn Ellis 4 years, 9 months ago.

Topic Author Topic
Posted: Tuesday Mar 13th, 2012 at 3:58 pm #8041
Norm Sash
Username: NormsIM

The default role that S2 assigns for new users is “subscriber”. I’m trying to figure out how to changes that and have found multiple topics on it in the forums, but can’t seem to get it to work. Here’s what I need… I have a WP user role defined as “Calendar Contributor” which has the capabilities to edit calendar post types (slightly more capabilities than “subscriber”. I want to have “Calendar Contributors” be the default role.

I tried the “User role editor” plugin which has the capability to define default roles… except that it gives an error whenever I try to assign “Calendar contributor”, I think becasue S2 is forcing it back to one of the subscriiber, contributor, author, editor roles.

I also found an s2-hacks.php per the following, but it gives a similar result. With the following code in s2-hacks.php I get a “none” role assigned.

Any ideas how I can set this up so that Calendar contributor is the default role? And do I need to give “Calendar Contributor” S2-level 0 capabilities?

-Norm

  • This topic was modified 4 years, 10 months ago by  Norm Sash.
  • This topic was modified 3 years, 4 months ago by  Norm Sash.

List Of Topic Replies

Viewing 15 replies - 1 through 15 (of 15 total)
Author Replies
Author Replies
Posted: Tuesday Mar 13th, 2012 at 8:17 pm #8063
David Welch
Username: dwbiz05

Have you tried using lower case and underscore in your spaces instead of the way it appears on the screen?

<?php
	add_filter("ws_plugin__s2member_force_default_role", "default_role");
	function default_role($role){
		$return = 'calendar_contributor';
		return $return;
	}
?>

Hope that helps,

Dave

EDIT: I believe you will need to pass the s2member level capabilities to your custom role as well. Not 100% sure, but I think so.

  • This reply was modified 4 years, 10 months ago by  David Welch.
Posted: Wednesday Mar 14th, 2012 at 5:27 am #8101
Posted: Wednesday Mar 14th, 2012 at 4:50 pm #8162
Norm Sash
Username: NormsIM

Thanks for the suggestings, guys… got it to work! It was a combination of both of your suggestions. The final code that worked is below. I don’t understand why the “Calendar Contributor” had to be entered as “calendar_contributor” when all the references I see to it on my sites roles is as “Calendar Contributor”, but it probrably has to do with internal pointer verses displayed content. I’m not sure how to display the internal pointer. But anyway, it works. And I did have to follow the suggestion of passing the number of arguments (I assumed 1) to get it to work.

<?php
	/* Forces the default role of a new user to be set to "Calendar Contributor" instead of "Subscriber" */
	add_filter("ws_plugin__s2member_force_default_role", "default_role",10,1);
	function default_role($role){
		$return = 'calendar_contributor';
		return $return;
	}
?>
<?php
	/* locks custom roles and capabilities from being reset during S2 upgrade */
    add_filter("ws_plugin__s2member_lock_roles_caps", "__return_true");
?>
Posted: Wednesday Mar 14th, 2012 at 6:07 pm #8176

Glad you got it working.

Yeah, roles are lowercase, just had that issue with another customer who sorted it out today as well.

About the arguments, you can see them in the page I linked to.

Posted: Wednesday Mar 14th, 2012 at 9:14 pm #8191

I’m using S2member Free 120219 and had a similar problem: I wanted new registered users to be on #Level 1 membership but if I use the User Role Plugin to change the default one (Suscriber) to #Level 1 it gives me an error.
Should I then forge an s2-hacks.php similar to the one presented forcing the #Level 1 to new registered users? is it possible?

Posted: Wednesday Mar 14th, 2012 at 11:14 pm #8194
Norm Sash
Username: NormsIM

I’m not sure if there is another work-around other than the one above. I still get an error in the User Role plugin if I try to set the default level to specific roles. It seems that I can set the default level to some of the standard WP roles (subscriber, contributor, editor, author, etc), but if I try to set it to any of the other roles, e.g. S2 Member, I get the error messages. If I keep trying for whatever reason sometimes I can get the requested role to be accepted, but then when I come back into User Roles I get another error.

Not sure where the conflict is – possibly S2 forcing a specific default role and not allowing User Roles to specify one???

But try similar code to the code in this thread and maybe it will work. This is an unsupported forum but maybe someone at S2 will notice this and figure out what the conflict is with the ability of User Roles to set a default role.

Posted: Thursday Mar 15th, 2012 at 9:51 am #8232

Norm, I have noticed that in line 3 of your code that starts with “add_filter… after default_role you put “10,1”. What are the meanings of “10” and “1”? are they the default values of $priority and $accepted_args? sorry, I’m new with S2Member and PHP..

  • This reply was modified 4 years, 9 months ago by  Mark Ngbapai.
Posted: Thursday Mar 15th, 2012 at 10:35 am #8238
David Welch
Username: dwbiz05

yes, they are.

Priority tells the system when it should be run in the processing order.
Accepted args states how many arguments from the filter should be passed to your function.

Dave

Posted: Thursday Mar 15th, 2012 at 11:10 am #8252

Thanks Dave, I’ll try the s2-hacks.php workaround and see if it works..

Posted: Thursday Mar 15th, 2012 at 1:02 pm #8265

Thanks you all, guys! you have made my day with this thread. I’ve included the code in my s2-hacks.php and now under the User Role Editor, the default new user role is now successfully set to “s2Member Level 1” and as of now, it’s not giving me errors anymore. I’m very grateful for that.

  • This reply was modified 4 years, 9 months ago by  Mark Ngbapai.
  • This reply was modified 4 years, 9 months ago by  Mark Ngbapai. Reason: typo
Posted: Thursday Mar 15th, 2012 at 2:04 pm #8274
Eduan
Username: Eduan
Moderator

Excellent!

Thanks for getting back to us. :)

Posted: Monday Mar 19th, 2012 at 10:58 am #8534
Shawn Ellis
Username: sspeak

Hi All –

I’m looking for a solution that would allow members of my site to add/edit posts on my site. I understand that this is not part of the core functionality of s2member, but I also understand that there are workarounds.

Is the “s2-hacks” mentioned above a solution for this?

I have the Members plugin and I’ve tried using that to edit/assign capabilities so my s2member role, but that doesn’t seem to be my solution. (The s2members still don’t show up as possible authors for blog posts.)

Thank you for any help/guidance. Please let me know if there is another post that addresses this.

Best,
Shawn

Posted: Monday Mar 19th, 2012 at 11:55 am #8539
Norm Sash
Username: NormsIM

I don’t believe that the s2-hacks is the solution for you, but maybe you can confirm my understanding of what you are doing. What you want to do is give someone author or editor rights when they become a paid subscriber via S2.

You memtion that you use the Members plugin to edit/assign capabilities. Do you mean that you are using the “User Roles Editor” plugin, or are you editing capabilities in a different manner. My thought would be that you could assign editor rights to the S2 level that is appropriate and that should work for what you want to do… s2-hacks would be unesessary in that case.

Norm Sash
http://nerdmans.com

Posted: Monday Mar 19th, 2012 at 11:59 am #8540
David Welch
Username: dwbiz05

Shwan,

check out this post:

http://www.s2member.com/forums/topic/nned-help-please/#post-6802

Hope it helps,

Dave

Posted: Monday Mar 19th, 2012 at 5:02 pm #8561
Shawn Ellis
Username: sspeak

Norm and Dave – Thanks for your replies.

I want to give someone who joins through s2member author/editor privileges for a custom post type, and also for normal posts. As far as the plugin I’m using, it’s the Members plugin which has role management capabilities: http://wordpress.org/extend/plugins/members/.

It seems that this offers the same role management functionality as User Role Editor, but maybe I need to compare the two.

I’ve given s2member_level2 the following capabilities:
edit_posts
delete_posts
edit_published_posts

But when I go to an existing post, an s2member in Level 2 is not listed in the drop-down of possible authors.

Am I missing something?

I don’t see anything in the capability list that indicates editing my custom post type. Would I need to add a custom capability for that?

The fact that it’s not working right for “normal” posts tells me something else must be wrong, though.

Thank you,
Shawn

Viewing 15 replies - 1 through 15 (of 15 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.