Support Forum
Hello - I have a test site set up and I'm using Memberpress, Buddypress & Simplepress w/Buddypress integration.
I have several Memberpress membership levels, and I'd like certain memberships to be granted access to certain Simplepress forums upon signup. I have created memberships named "limited", "premium" & "cms_faculty"; each will have a corresponding forum.
I have created custom WP Roles based on these these membership names. (Memberpress provided me with a custom plugin that assigns new members at time of sign up to these WP Roles based on the matching membership mentioned above).
In Simplepress I created forums and user groups for each of these groups, and assigned the specific permissions needed. (see attached screenshots). I then set the user group mapping based on WP Roles.
Simplepress seems to be working fine and recognizing the forum permissions once I get a user into the correct User Group; however Simplepress is not putting them in the correct user group based on their WP Role.
When I create a new user via Memberpress membership signup, they are correctly assigned to the right custom WP Role. Simplepress seems to be ignoring the "Usergroup memberships based on WP role" that I set up and instead is using the "Default usergroup membership".
What do I need to do to get Simplepress to use the "Usergroup memberships based on WP role" for new signups?
Thanks,
Kelly
FYI - I stumbled across a similar post here in the forums, but I don't fully understand it:
https://simple-press.com/suppo.....on/page-2/
It appears the issue was resolved with some implementation of 'set_user_role', however I don't fully understand it.
Here is the plugin code that I am using to automatically assign new Memberpress membership levels to WP Roles; perhaps a set_user_role needs to also happen when this code runs?
function memberpress_user_role($txn) {
$user = get_user_by('id', $txn->user_id);
//user doesn't exist for some reason, or is an admin - we don't want to wipe out the admin's role haha
if($user === false || user_can($txn->user_id, 'manage_options'))
return;
//Leave the user's WP Role alone, and just add a bbPress Role to them
if($txn->product_id == 25) { //User purchased membership 25: CMS_faculty
$user->remove_role('subscriber');
$user->add_role('cms_facility_role');
return;
//Leave the user's WP Role alone, and just add a bbPress Role to them
} elseif($txn->product_id == 23) { //User purchased membership 23: limited
$user->remove_role('subscriber');
$user->add_role('limited_role');
return;
//Leave the user's WP Role alone, and just add a bbPress Role to them
} elseif($txn->product_id == 24) { //User purchased membership 24: premium
$user->remove_role('subscriber');
$user->add_role('premium_role');
return;
}
}
add_action('mepr-txn-status-complete', 'memberpress_user_role');
I am not sure how this memberpress works... when this plugin assigns a new user the wp role, does it properly use the wp api for this so that appropriate hooks are fired? if it just manipulates it via the db, then no way for us to know that the wp user got the role..
the code in your second post actually does use the wp api to set the role (ie the $user->add_role function call)... so when that is done, wp notifies plugins such as simple press that the user got the role, so we can act appropriately...
Visit Cruise Talk Central and Mr Papa's World
Hi - thanks for the response!
I don't know if Memberpress properly uses the WP API; I will ask them directly.
The code I posted was provided by them, with the extra IF's added by me. The code works - that is, Wordpress knows that the person is now in whatever new custom WP Role they've been assigned to.
Previously, you discussed this issue with another user in the post below, and you suggested that "set_user_role" was necessary; that add_role by itself was insufficient.
https://simple-press.com/suppo.....on/page-2/
It would seem to me that if the user has gotten the custom WP Role, wouldn't Simplepress recognize the user is a member of that group? That is what does not seem to be happening.
Kelly
ah, several years ago... and it was a deficiency in wp... and looks like one they have corrected... though they use a different hook for it too...
so for now, just try changing
$user->add_role
to
$user->set_role
and it should work...
Like the wp did make an update, but looks like we need to check for the new add_user_role hook as well... and I will open a ticket for that...
Visit Cruise Talk Central and Mr Papa's World
thanks for the confirmation... and as mentioned, we will get the additional wp hook that was added in use as well on our end in the next version...
Visit Cruise Talk Central and Mr Papa's World
Mr Papa - This dialog with you and with Memberpress support has prompted them to want to add user role support to the UI of Memberpress. They have a question for you:
Do they currently use the add_user_role and remove_user_role action hooks from WordPress also, or do they only look at the set_user_role hook?
I think I know the answer to this but wanted to hear it from you if possible. Thanks!
Memberpress also has a suggestion, which you may have already thought of, but for the sake of thoroughness let me post it here
Paul replied
May 17, 11:48am
It would be great if they could check for add_user_role AND remove_user_role. That way we could set up our addon to both add/remove roles from user's as they become active/inactive on membership levels.
It can notify plugins if they setup a proper callback for the hooks:
Add A Role Hook: https://github.com/WordPress/W.....r.php#L524
Remove A Role Hook: https://github.com/WordPress/W.....r.php#L551
Set User's Role Hook: https://github.com/WordPress/W.....r.php#L594 (It sounds like they're only using this one currently)
Depends..... How about that? 🙂
Actually depends on whether you want or need users to have more than one role.
In general, I think single role makes more sense... So I would use the set role. .
Visit Cruise Talk Central and Mr Papa's World
1 Guest(s)