Home » Code Examples » Custom session limit for specific user

March 26, 2021

Custom session limit for specific user

In some cases you might want to set a custom session limit for a user. This becomes a really handy snippet if for example an external api or some custom usermeta determines how many sessions a user is allowed to have.

// Set limit for user with ID 8 to 10 sessions
add_filter("session_limit", "increase_limit_user", 99, 2);
function increase_limit_user(int $limit, WP_User $user) {
    if ( $user->ID == 8 ) {
        return 10;
    }
    return $within;
}

How to add this code snippet?

We recommend that you add the code snippets to your themes functions.php file. Make sure you create backups before you add any customization. Please make sure that you always have a plan ready if a code snippet causes errors. Detailed information about how to add code snippets to your WordPress installation can be found here: wpbeginner.com

Need help customizing session manager?

You are looking for a custom solution, to make the session manager truly fit your needs? No problem we got you covered. Simply send us a short briefing about your requirements and we send you a quote if there is not already a solution. If your problem requires changes on the plugin and we think the new functionality might be a feature many users would like, we implement it in the core of our plugin. This way you profit from features others requested and also be an awesome part of the community.

Leave a Reply

Your email address will not be published.