How To Exclude Specific User Roles From The Session Expiration (Hook)

In this knowledge base article, we will guide you on how to exclude specific user roles from the session expiration.

Let’s get started.

Before diving into the session expiration based on roles, you need to understand “Session Expiration.”

What is Session Expiration?

Session Expiration is the timeout frame of WordPress Sessions, which are designed to expire within a specific limit by default. It causes  "WordPress Session Expired" errors if a custom timeout is not set. 

In our case, “Login Session” is being used, which has a timeout frame of 2 Days or 48 days by default. if you check the “Remember Me” box, this timeout frame is increased to 14 days.

Default Session Expire Error

However, this comes with security concerns for which LoginPress provides “Session Expiration” functionality. With this, you can increase or decrease the login session expiration in Minutes.

Session Expire - LoginPress
Session Expire - LoginPress

Note: You can also check out our guide on How to Customize the Session Expire Time in WordPress 

Why Exclude Specific Users From the Session Expiration?

Let's say you have an editor role or custom user role that needs more time than defined in your login session expiration settings.

LoginPress got you covered for this.

You can exclude the specific user roles from LoginPress Session Expiration, allowing them not to get pushed out of WordPress Session. Because excluding specific users, i.e., the Administrator or Editor of your WordPress would help to avoid unnecessary logins and content loss while editing, etc.

Excluding Specific User Roles From the Session Expiration With Hook

Suppose you want to exclude the Administrator and Contributor from the session expiration. All you need to do is to add the following line of code in your Child Theme's file functions.php and update the file.

function loginpress_exclude_role_session_callback() { 
return array( 'administrator', 'contributor' );
add_filter( 'loginpress_exclude_role_session', 'loginpress_exclude_role_session_callback' );

Coding Too Confusing? 

Here is an explanation of what this is, here you can return a single value or array of the roles. This array will be containing the slugs of roles here are the roles which you can use by default, You can use custom roles as they are created as well.

User Roles: 

  • Super Admin – User with access to the site network having administration features and all other features. 
  • Administrator (slug: ‘administrator’) – User access to all the administration features within a single site.
  • Editor (slug: ‘editor’) – A user who publish and manages posts including the posts of other users.
  • Author (slug: ‘author’) – A user who can publish and manage their own posts.
  • Contributor (slug: ‘contributor’) – A user who can write and manage their own posts but cannot publish them.
  • Subscriber (slug: ‘subscriber’) – somebody who can only manage their profile.

That's all! You can exclude specific user roles from the session expiration with the above hook.
If you have any doubts or questions related to this matter, please don’t hesitate to reach out to our support team.

Still stuck? How can we help?

Updated on October 31, 2022

LoginPress Support
triangular shape yellowish icon

Frequently Asked Questions (FAQs)

These FAQs answer the most common questions about our WordPress custom login page plugin.

three shapes icon

Is LoginPress WPML Compatible?

LoginPress is fully supported with multilingual. LoginPress is also compatible with WPML Plugin, which means you can easily translate your login page with WPML plugin according to the given translation options in the WPML plugin.

Is LoginPress translation ready?

Yes, LoginPress has full translation and localization support via the LoginPress textdomain. All .mo and .po translation files should go into the languages folder in the base of the plugin.

Is coding skills needed to use LoginPress?

No, It is very easy to setup. Just plug and play. Have fun!

How to Install or Use LoginPress Pro?

Step-by-step instructions on How to Upgrade from existing Free version to Pro
1. You have installed and set up the Free version already.
2. Upload the Pro version.
3. Pro features will be enabled automatically.
4. You don’t need to set up Free version options again.
5. Setup Pro features like Google fonts, Google reCaptcha, Choose themes, etc.

Where is my license key?

License key is the Order ID which looks like in this format.
You can find it in the email Sales Receipt.

three shapes icon

If you Still have Questions?

Get In Touch