Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
coding-topic
Membership integration
Avatar
Simon Trice
Wales
Member
Free Members
sp_UserOfflineSmall Offline
Feb 10, 2016 - 1:48 pm

I am using the Simple Membership plugin to control access to the site and would like to deny posting ability to members with expired subscriptions.  Is there an easy way to do this, maybe with an authorization?

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Feb 10, 2016 - 5:12 pm

There is an easy way to do this if the membership plugin utilises the WP standards correctly. And that is with Wp role mapping (forum admin > user groups > map users to user groups. This can automatically move users from one forums user group to another (i.e., with differing permissions) with their status change but it does relate to WP roles.

This FAQ discusses how to set SP up with a membership plugin - in this case WishList Member - but th e process and theory is the same...

https://simple-press.com/docum.....ip-plugin/

andy-signature.png
YELLOW
SWORDFISH
Avatar
Simon Trice
Wales
Member
Free Members
sp_UserOfflineSmall Offline
Feb 11, 2016 - 2:48 am

Thanks, but I have already done that.  Simple membership adds a flag to the account of 'expired' which still allows the user to log in so they can renew their subscription but leaves their user role alone. 

I can get the user's expired status with a pip function and would like to be able to check for that as a second authorization.

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Feb 11, 2016 - 3:04 am

Well - the natural methodology that Simple:Press adopts is to move a user from one user group to another - i.e. if you took our default user groups as installed - it could move someone from the members group into the guests group (for example) which can be automatically achieved by role mapping. And that has no impact ion whether a user can log in or not as login is not a function of Simple:Press bit a function of your website. 

So it sounds like your membership plugin is unable to do this. Which would mean, perhaps, a coded solution which is probably easy to achieve.

Perhaps a little more detail then would help us to advise on the options. You said at top that you would like to 'deny posting ability'. Does that mean you want to make the forums read-only? Or you want to remove them completely? If you can describe what you want to happen it will make it easier..

andy-signature.png
YELLOW
SWORDFISH
Avatar
Simon Trice
Wales
Member
Free Members
sp_UserOfflineSmall Offline
Feb 11, 2016 - 3:39 am

hi

what I want to do is basically move the member to the guest group for as long as their subscription flag is set to expired.  If they then renew they will be moved into the members group.  The problem with the group mapping is that it does not see the subscription flag as an option so cannot pick up on it.  It will definitely need to be a coded solution, I am hoping that this can be achieved through added functions to the theme?

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Feb 11, 2016 - 3:51 am

I don't know, of course, how familiar you are with WordPress coding so please excuse me if I aim this too high or too low!

WordPress allows plugins to interact with the core by the use of 'hooks' (filters and actions) which you can think of as a sort of messaging system. Any decent plugin, especially one that may have to inform other plugins - should implement their own series of hooks. 

In the case of what you want to do you are needing an 'action' hook that your membership plugin implements after they change this flag. If you know this - and know the data it sends - then we can work out the best SP functions to call to change a users user group.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Simon Trice
Wales
Member
Free Members
sp_UserOfflineSmall Offline
Feb 11, 2016 - 4:32 am

I have trawled through the code for the simple membership plugin, they have no api and only a few hooks for the login validation process.  The expired status is set by a direct database edit handled by a cron job that runs every day.  They do have a way to check that flag though.

if(SwpmMemberUtils::is_member_logged_in()) {
    $auth = SwpmAuth::get_instance();
    $expired = $auth->get('account_state');
 
 //handle member switch here
}

Maybe hook into the wp login process and move the user to guest after running this check?

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Feb 11, 2016 - 5:13 am

Well - of course I can not really condone hacking into any code when there is a perfectly good API to utilise but still... 

The functions you will need to look at are in the /simple-press/sp-api/sp-api-users.php file. They are:

sp_remove_membership($usergroup_id, $user_id);
sp_add_membership($usergroup_id, $user_id);

This is where using the API helps though. If done through a hook we would be making sure all the necessary support code was loaded but within those 2 functions a few more files would also need to be included. 

if I was you - and was 'hacking' here then personally I would just take a look at the SQL being applied and just use that. Two simple queries is all that is needed for the remove and add operations.

But you will also need to perform a clear of the 'memberships' and 'auths' columns for the user in the 'sfmembers' table because the data in there is cached so would need to be rebuilt.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Simon Trice
Wales
Member
Free Members
sp_UserOfflineSmall Offline
Feb 11, 2016 - 12:48 pm

Hi swordfish

Many Thanks but it seems a lot to go through with a good possibility that I will probably do something wrong and break everything.

 

Instead I am looking at adding a new hook into the simple membership cron-job that will allow me to run a function on any member who gets changed to expired.  I can then add a function to my theme functions to change the user role to a custom role I have added and mapped to the guest group of the forum.

Seems like an easier way forward. I am just waiting to hear back from the plugin developer ( to make sure my alteration won't break anything).

I'll keep you informed, it may be useful to other users who want to use simple membership and simple::press together.

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Feb 11, 2016 - 3:05 pm

Absolutely - get the hooks in place and it makes everything so very much more seamless and easier.

andy-signature.png
YELLOW
SWORDFISH
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 649
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 618
Members: 17357
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10123
Posts: 79616