# Only allow access when user has a subscription plan on Memberpress

**URL:** <https://meta.discourse.org/t/only-allow-access-when-user-has-a-subscription-plan-on-memberpress/188716>\
**Category:** WordPress\
**Created:** [April 30, 2021, 3:39pm UTC](https://meta.discourse.org/t/only-allow-access-when-user-has-a-subscription-plan-on-memberpress/188716 "2021-04-30T15:39:32Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [April 30, 2021, 8:26pm UTC](https://meta.discourse.org/t/only-allow-access-when-user-has-a-subscription-plan-on-memberpress/188716/7 "2021-04-30T20:26:12Z")

</div>

> [@Per\_Jacobsson1](#):
>
> how long is a user logged into Discourse before being logged out?

This is controlled by the Discourse `maximum session age` site setting. That setting defaults to 1440 hours. Unless it is set to a very small value, it is not a reliable way to log out users. That is because it sets the amount of time that a user will remain logged in since their _last visit_. Setting `maximum session age` to a very small number of hours could also cause some annoyance for your site users.

I think your best approach would be to log users out of Discourse through the API when memberships expire. There is a code example of how to do that here: [wp-discourse/lib/sso-provider/discourse-sso.php at main · discourse/wp-discourse · GitHub](https://github.com/discourse/wp-discourse/blob/master/lib/sso-provider/discourse-sso.php#L205). You might need to get some help from a developer to make an API call to log users out of Discourse when their membership expires.

---

_[View the full topic](https://meta.discourse.org/t/only-allow-access-when-user-has-a-subscription-plan-on-memberpress/188716)._
