Envira Gallery Documentation

Documentation, Reference Materials and Tutorials for Envira Gallery

How to customize the Password addon cookie

The Envira Gallery Password Addon provides an extra layer of security by requiring a password to view certain galleries. By default, once accessed, the gallery uses cookies to remember that the user has entered the correct password, preventing repeated prompts. For enhanced control, you may want to adjust the duration of this cookie. This tutorial will teach you how to set a custom cookie time limit for the Envira Gallery Password Addon.

Heads up!
This article includes PHP customization to modify gallery password protection settings. The code here is shared as a courtesy, and we don’t provide support for additional customizations or third-party development.

Adding the Code Snippet

To set a custom time limit for the password protection cookie in Envira Gallery, use the following code snippet. For guidance on adding custom PHP code to your WordPress site, refer to this document.

Here’s the code snippet to implement:

/* Control the Cookie for the Password Addon
 * 
 * @link https://enviragallery.com/docs/how-to-control-the-cookie-for-the-password-addon/
 */

add_filter('envira_password_protection_time_limit', 'test_envira_password_protection_time_limit', 10, 3);
function test_envira_password_protection_time_limit($time_limit, $post, $data) {
    // Note: you can use $post and $data to individually set time limit based on post ID, gallery data, etc.
    // Time is in seconds, so if you wanted to set the time limit for something very short (like 10 seconds)
    $time_limit = time() + 10;
    return $time_limit;   
}

Customizing the Snippet

  • Functionality:
    • The envira_password_protection_time_limit filter allows you to define how long the password cookie remains active.
    • In the snippet, $time_limit = time() + 10; sets the cookie duration to 10 seconds as an example. Modify this value to suit your needs (e.g., 3600 for 1 hour).
  • Dynamic Adjustment:
    • You can leverage $post and $data to create conditions that alter the time limit based on specific galleries or posts.

Summary

Customizing the password protection cookie duration can offer tailored security measures for your galleries, ensuring the experience aligns with your site’s requirements. Adjusting the cookie duration can be particularly useful if you need more frequent reauthentication or longer access periods.

And that’s it! Would you like to have your gallery titles link when inside an Envira album? Take a look at our article on How to make the gallery titles in your Envira Albums link.