Learn in this tutorial how to allow a user role to have a custom simultaneous access limit using the Loggedin plugin, through code.
If you have a membership, you may want to limit the number of simultaneous logins of your subscribers. And one option to do this is by using the Loggedin plugin.
But, if you have several membership levels, you may want to offer (in exchange for a higher price, for example), the option to not apply this restriction as we saw in your previous tutorial or, better yet, customize the number of users that can be connected at the same time, as you are going to see in this tutorial.
Snippet to customize the number of simultaneous logins according to user role
Imagine that, in a membership created with EDD + Recurring Payments, you want to offer, in addition to the individual membership level, a couple of levels for schools, so that a certain number of users can access at the same time.
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
In this case, you use the loggedin_reached_limit
filter to indicate that the user roles edd_subscriber_school_1
and edd_subscriber_school_2
have a specific limit of simultaneous accesses applied to them. In this case, 25 for the former and 50 for the latter.
The role to which the exception applies in this case is edd_subscriber_school_1
and edd_subscriber_school_2
but the idea is that you change them to the user role of your choice. You will need to create them first by following the tutorial where I explain how to create a custom user role.
Continuing with the same example, you could use something like this:
To see this and another 1097 code snippets of this website, login or subscribe here.
If you are using Easy Digital Downloads to create the membership, you may also be interested in the tutorial where I explain how to assign a custom user role depending on the product being purchased.
Conclusion
As you can see, with a few lines of code you can customize the limitation of simultaneous accesses according to the user role.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂