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 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 January 3, 2024

Documentation
triangular shape yellowish icon

Frequently Asked Questions (FAQs)

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

after animated element
three shapes icon

Where can I get support for LoginPress?

If you need help with LoginPress, you can contact us here. We’ll be happy to answer any questions about the plugin.

Do you have an affiliate program?

Yes, we have an affiliate program that you can sign up for here. As an affiliate, you’ll earn a commission on every sale you refer to us.

Do you offer refunds?

Yes, we offer a 14-day money-back guarantee on all of our plans. If you’re unsatisfied with LoginPress, simply contact us within 14 days of your purchase, and we’ll process a refund.

Can I upgrade my license after my initial purchase?

Yes, you can upgrade your LoginPress license at any time. Simply log into your account and go to the My Downloads page. From here, you can upgrade your license and download the latest version of the plugin.

Will LoginPress slow down my website?

No, LoginPress will not slow down your website. The plugin is lightweight and only loads the necessary files when someone tries to access your login page.

three shapes icon

If you Still have Questions?

Get In Touch
Hurry up!! Limited Time Offer  - Get  20% Off  on LoginPress 
Discount Code: EARLY20 
Special Offer on LoginPress
close-image