Home » Code Examples » Whitelist user roles

March 26, 2021

Whitelist user roles

When using the wp_login integration you might find yourself locked out even as admin or editor. To avoid this you might want to add a user role based whitelist.

// Whitelist user roles
add_filter("is_within_session_limit", "whitelist_roles", 99, 2);
function whitelist_roles(bool $within, WP_User $user) {
    $allowed_roles = array( 'editor', 'administrator', 'author' );
    if (array_intersect( $allowed_roles, $user->roles )) {
        return true;
    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. Required fields are marked *