Changing free levels

l am looking for a form to switch a level up or down.

I have level 0, 1 an 2.
Levels 0 and 1 should be free and users should have the possibility to switch between this levels up and down.

A user with level 0 has:

To upgrade I use:

[s2Member-Pro-PayPal-Form modify=“1” level=“1” ccaps="" desc=“Kurse, Quizze und kleine Umfragen erstellen und anbieten, es ist kostenlos!” custom=“einfachalles.at” tp=“0” tt=“D” ra=“0.00” captcha=“0” /]

Then the user has no role:


That‘s not, what I want. The user should have the label of level #1

What is wrong with my form?

franzl

I’d have to check the code that processes the form, but I know they’re not meant for free role changes. You can do a free signup, but not free level changes with them. I suppose the odd behavior you see in the role may be coming from that…

Instead you could use a bit of PHP that’ll change the user’s role. See:

But I can see how it’d be simpler to have a way to do it without a customization. I’m adding it as a feature request with your vote.

:slight_smile:

Your last sentence makes me happy :slight_smile:

In the meantime I test my problem with an absolutely fresh installation on another non productive domain:


I wrote a test page:

Before and after viewing/executing the code on the page my userlist in the backend is the same:

I have to admit that I obviously don’t understand enough about the subject, but I expected that a user with user-id 123 would be created and assigned the role s2member_level1. :frowning:

franzl

No, user 123 is not created, an instance of the WP_User object, using the 123 user data, would be created… This doesn’t create a wordpress user, you’d create it or he’d signup, as they normally do. Then this script would pick up this existing user’s account and change its role to Level 1.

Instead of a hard-coded user ID (i.e. 123) you’d use the current user’s ID (only if he has a subscriber role and is not an administrator, you need to add this check or you could demote your own account by mistake).

Something like this, in a page shown only to logged in users:

<?php
if (current_user_is_not('administrator') AND current_user_cannot('access_s2member_level1') {
  $user = new WP_User(S2MEMBER_CURRENT_USER_ID);
  $user->set_role("s2member_level1");
}

See also:

https://www.s2member.com/codex/stable/s2member/api_constants/package-globals/

https://www.s2member.com/codex/stable/s2member/api_functions/package-summary/

:slight_smile:

Thank You!
In the meantime, I’ve become a little more familiar with PHP. I’ve put together a solution that works for me.

Happy New Year and
Best Regard,
franzl

1 Like