Update has broken s2member_access_level retrieval?

Hi,

i’m wondering if something recently changed to make my code stop working…

I was using:

//demote user
update_user_option ($user_id, “s2member_access_level”, 0);

and

//promote user
update_user_option ($user_id, “s2member_access_level”, 1);

to promote and demote users, however the promote to level 1 code no longer works. since a couple of weeks.

Is this still a valid way to do this, or do i need to update my code to use:

$user_id = $user_id;
$user = new WP_User($user_id);
$user->set_role(“s2member_level1”);

and if so how do I update the following to get a number based upon the s2member_access_level:
$s2member_var = get_user_field (“s2member_access_level”, $sub_id);

Thanks for any replies!

So i’ve had a look in the user_meta database table, and it looks like a recent update has changed:

{your-db-prefix}_s2member_access_level

to

{your-db-prefix}_user_level

Can anybody do me a solid and check whether the same has happened to their table, or whether it’s just something that has happened to me?

Thanks!!!

So i’ve had a look in the user_meta database table, and it looks like a recent update has changed:
{your-db-prefix}_s2member_access_level to {your-db-prefix}_user_level

What update was that? s2Member didn’t change the way it names that. the user_level one doesn’t seem related to s2’s access level one.

Is this still a valid way to do this, or do i need to update my code to use:

I think you could try the $user->set_role(“s2member_level1”) one, and update your customization with it. https://s2member.com/kb-article/rolescapabilities-via-php/

:slight_smile:

Thanks for your reply Christian, I see the rumours of your demise are just that!

I have had some success with the following code:
//promote user
$user = new WP_User($user_id);
$user->set_role(“s2member_level1”);

//demote user
$user = new WP_User($user_id);
$user->set_role(“s2member_level1”);
foreach ($all_role as $role_value){
$user->remove_role($role_value);
}
$user->set_role(“subscriber”);

it is possible I have made an error at some point recently that has programatically changed the name of the database field from:
{your-db-prefix}_s2member_access_level
to
{your-db-prefix}_user_level

would you be able to confirm that the way that the level is stored is via: {your-db-prefix}_s2member_access_level

if so I can change it back and hopefully that will fix things

Kind Regards

Brett

1 Like

Thanks for your reply Christian, I see the rumours of your demise are just that!

:kissing_heart:

I have had some success with the following code:

Great!

would you be able to confirm that the way that the level is stored is via: {your-db-prefix}_s2member_access_level

In my tests installation I have wp_user_level rows in usermeta, but these are not created by s2, and don’t affect s2’s behavior. I’m not sure if WP creates these or it’s something else.

s2’s level is a wordpress role, and access capabilities, s2 doesn’t save it as a usermeta entry named like that. https://s2member.com/kb-article/s2member-rolescapabilities/

If you search for s2member_level in the usermeta values, for example, you’ll see it mentioned in the wp_capabilities rows.

:slight_smile:

OK, thanks. I can see the capabilities metadata but for some reason update_user_option ($user_id, “s2member_access_level”, 1); just does not seeem to do anything.

It was working a couple of weeks ago, Oh well I guess I can continue using my amended code.

Thanks

Brett

1 Like