Skip to content

HandyPlugins

  • Home
  • PluginsExpand
    • Magic Login Pro
    • Handywriter
    • WP Accessibility Toolkit
    • PaddlePress Pro
    • Easy Text-to-Speech
  • Docs
  • About
  • Blog
  • Contact
My Account
HandyPlugins
Popular Search shortcodethehookemailredirect

Magic Login Pro

36
  • Installation & Configuration
  • Use magic login as the default login method?
  • Brute Force Protection
  • WooCommerce Integration
  • Easy Digital Downloads (EDD) Integration
  • Token Lifespan
  • Disable Magic Login for a Specific User
  • Login with Code: Flexible Passcode-Based Authentication
  • SMS Login – Passwordless Authentication with SMS
  • Magic Login REST API
  • QR Code Login
  • CLI Command
  • Add Login form to a Page
  • Reset Tokens
  • Auto Login Links
  • Token Validity
  • Login Redirect
  • Shortcode
  • Login Email Customization
  • Login Request Throttling
  • IP Check
  • Domain Restriction
  • Registration
  • Spam Protection
  • How to Add Magic Login to Any of Outgoing Emails?
  • Customize Default Messages
  • nG Firewall
  • Dynamically Adjust Token TTL
  • How to change Sender Details?
  • Disable Magic Login for specific roles
  • Customizing Login Session Duration
  • Magic Login Twilio Integration
  • Magic Login – FluentCRM Integration
  • Reset Magic Login Links for a User
  • Hooks
  • Tools – Reset, Export & Import Magic Login Settings

PaddlePress Pro

26
  • Installation & Configuration
  • How does PaddlePress PRO work?
  • Automatic account creation
  • How to set up a membership website?
  • Setup a Development Environment
  • Protect Download Files on NGINX
  • Software Licensing
  • Software Licensing API
  • Updater Implementation for WordPress Plugins
  • Updater Implementation for WordPress Themes
  • Release a New WordPress Product
  • Customer Dashboard (My Account) Page
  • Checkout Buttons
  • Custom Redirect After Successful Checkout
  • How does the domain count?
  • Emails
  • Accessing Readme through a Shortcode
  • How to Sell WordPress Products?
  • Releasing Beta Versions of a WordPress Product
  • Paddle Billing
  • Customer Dashboard
  • Membership Levels
  • Restrict Content
  • Add a Custom Payment Action
  • How to customize “Download” Button?
  • Adding Manual Payments

Handywriter

11
  • Installation & Configuration
  • Write a Blog Post
  • Create a Summary
  • Suggest a Title
  • Keep records of AI generated Contents
  • Grammar & Spelling Fixer
  • Plagiarism Check
  • Content Templates
  • How to create a Meta Description?
  • How to complete a sentence?
  • How does credit calculation work?

Easy Text-to-Speech

5
  • Installation & Configuration
  • Using with Block Editor
  • Using with Classic Editor
  • OpenAI Integration
  • ElevenLabs Integration

WP Accessibility Toolkit

3
  • Customization
  • Hotkeys: Quick Navigation and Efficiency
  • Do not show the accessibility toolkit on the specific page

FAQ

1
  • How to Enter Your VAT Number for VAT Deduction at Checkout
  • Home
  • Docs
  • Magic Login Pro
  • Customizing Login Session Duration
View Categories

Customizing Login Session Duration

The Magic Login plugin makes logging in easy by using “magic links” instead of passwords. When a user logs in, their login session duration— the amount of time they stay logged in without needing to log in again — is controlled by a feature in WordPress called auth_cookie_expiration. This guide explains what login session duration is and how you can customize it for your site.

What is Login Session Duration? #

Login session duration is the amount of time a user stays logged in after using the magic link. Magic Login sets this duration automatically, ensuring users can stay logged in for a convenient amount of time. Developers or site administrators can customize how long users stay logged in by using WordPress’s built-in settings.

How Does Magic Login Handle Session Duration? #

By default, Magic Login sets the login session as if the “Remember Me” option is checked. This means users stay logged in longer, providing a smooth experience. However, you can adjust this duration based on your needs.

Customizing Login Session Duration with a Filter #

WordPress allows developers to customize login session durations with a special filter called auth_cookie_expiration. This filter lets you change how long users stay logged in, based on specific conditions like their preferences or user role.

The filter provides three pieces of information you can use:

  • $expiration: The default duration of the login session (in seconds).
  • $user_id: The ID of the user logging in.
  • $remember: Whether the “Remember Me” option is considered active.

Example: Adjusting Session Duration
Here’s how you can customize the login session duration by adding this code to your theme’s functions.php file or a custom plugin:

add_filter( 'auth_cookie_expiration', 'my_custom_cookie_expiration', 10, 3 );
function my_custom_cookie_expiration( $expiration, $user_id, $remember ) {
    // Extend session to 3 months if "Remember Me" is active
    if ( $remember ) {
        return 3 * MONTH_IN_SECONDS; // 3 months
    }

    // Otherwise, set session duration to 1 month
    return MONTH_IN_SECONDS; // 1 month
}

Example: Different Durations for Admins

add_filter( 'auth_cookie_expiration', 'role_based_cookie_expiration', 10, 3 );
function role_based_cookie_expiration( $expiration, $user_id, $remember ) {
$user = get_userdata( $user_id );

// Shorter duration for administrators
if ( in_array( 'administrator', (array) $user->roles ) ) {
return 7 * DAY_IN_SECONDS; // 1 week
}

// Default for all other users
return $remember ? 3 * MONTH_IN_SECONDS : MONTH_IN_SECONDS;
}

Why Customize Login Session Duration? #

Here are some reasons you might want to adjust the session duration:

  1. User Experience: Let users stay logged in longer for convenience.
  2. Security: Shorten session durations for sensitive accounts, like administrators.
  3. Business Needs: Match session lengths to your site’s use cases, such as frequent or occasional logins.

How to Test Your Changes #

  1. Add the filter code to your site.
  2. Log in as a user and confirm the session duration matches your settings.
  3. Use browser tools to check the expiration date of the login cookie.

Was this guide helpful for you?
Updated on November 25, 2024
Disable Magic Login for specific rolesMagic Login Twilio Integration
Table of Contents
  • What is Login Session Duration?
  • How Does Magic Login Handle Session Duration?
  • Customizing Login Session Duration with a Filter
  • Why Customize Login Session Duration?
  • How to Test Your Changes

HandyPlugins

Explore

Home
Blog
Contact Us
My Account

Products

Magic Login Pro
Handywriter
Easy Text-to-Speech
PaddlePress Pro
WP Accessibility Toolkit

Follow Us

Twitter
Facebook
GitHub
WordPress

2025 – HandyPlugins.co | Hosted on WPHandle and optimized with Powered Cache

  • Terms and Conditions
  • Privacy Policy
  • Cookie Policy
  • Home
  • Plugins
    • Magic Login Pro
    • Handywriter
    • WP Accessibility Toolkit
    • PaddlePress Pro
    • Easy Text-to-Speech
  • Docs
  • About
  • Blog
  • Contact
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkPrivacy policy